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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 80 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 81 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 82 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 83 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 84 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 85 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 86 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 87 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 88 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 89 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 90 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 91 | import android.telephony.AccessNetworkConstants; |
| 92 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 93 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 94 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 95 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 96 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 97 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 98 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 99 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 100 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 101 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 102 | import android.telephony.CellIdentityCdma; |
| 103 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 105 | import android.telephony.CellInfoGsm; |
| 106 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 107 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 108 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 110 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 111 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 112 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 113 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 114 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 115 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 116 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 117 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 118 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 119 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 121 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 122 | import android.telephony.SignalStrengthUpdateRequest; |
| 123 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 124 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 126 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 127 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 130 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 131 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 132 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 133 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 134 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 135 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 136 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 137 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 138 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 139 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 140 | import android.telephony.gba.GbaAuthRequest; |
| 141 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 142 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 143 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 145 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 146 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 147 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 154 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 155 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 156 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 158 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 160 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 164 | import android.telephony.satellite.NtnSignalStrength; |
| 165 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 166 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 167 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 172 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 173 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 176 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 177 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 178 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 179 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 180 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 195 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 212 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 213 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 215 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 218 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 219 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 221 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 222 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 228 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 231 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 232 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 233 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 234 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 235 | import com.android.internal.telephony.uicc.IccIoResult; |
| 236 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 238 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 239 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 243 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 244 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 245 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 246 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 247 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 248 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 249 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 250 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 251 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 252 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 253 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 254 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 255 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 256 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 257 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 258 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 259 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 260 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 261 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 262 | import com.android.services.telephony.TelecomAccountRegistry; |
| 263 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame^] | 264 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 265 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 266 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 267 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 268 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 269 | import java.io.IOException; |
| 270 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 271 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 272 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 273 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 274 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 275 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 276 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 277 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 278 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 279 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 280 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 281 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 282 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 283 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 284 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 285 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 286 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 287 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * Implementation of the ITelephony interface. |
| 291 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 292 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 293 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 294 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 295 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 296 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 297 | |
| 298 | // Message codes used with mMainThreadHandler |
| 299 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 300 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 301 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 302 | private static final int CMD_OPEN_CHANNEL = 9; |
| 303 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 304 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 305 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 306 | private static final int CMD_NV_READ_ITEM = 13; |
| 307 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 308 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 309 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 310 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 311 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 312 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 313 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 314 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 315 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 316 | private static final int CMD_SEND_ENVELOPE = 25; |
| 317 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 318 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 319 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 320 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 321 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 322 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 323 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 324 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 325 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 326 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 327 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 328 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 329 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 330 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 331 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 332 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 333 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 334 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 335 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 336 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 337 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 338 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 339 | private static final int CMD_SWITCH_SLOTS = 50; |
| 340 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 341 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 342 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 343 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 344 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 345 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 346 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 347 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 348 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 349 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 350 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 351 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 352 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 353 | private static final int CMD_MODEM_REBOOT = 64; |
| 354 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 355 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 356 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 357 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 358 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 359 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 360 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 361 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 362 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 363 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 364 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 365 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 366 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 367 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 368 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 369 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 370 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 371 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 372 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 373 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 374 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 375 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 376 | private static final int CMD_GET_CALL_WAITING = 87; |
| 377 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 378 | private static final int CMD_SET_CALL_WAITING = 89; |
| 379 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 380 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 381 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 382 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 383 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 384 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 385 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 386 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 387 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 388 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 389 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 390 | private static final int CMD_SET_SIM_POWER = 101; |
| 391 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 392 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 393 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 394 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 395 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 396 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 397 | 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] | 398 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 399 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 400 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 401 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 402 | private static final int CMD_ENABLE_VONR = 113; |
| 403 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 404 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 405 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 406 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 407 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 408 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 409 | // Parameters of select command. |
| 410 | private static final int SELECT_COMMAND = 0xA4; |
| 411 | private static final int SELECT_P1 = 0x04; |
| 412 | private static final int SELECT_P2 = 0; |
| 413 | private static final int SELECT_P3 = 0x10; |
| 414 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 415 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 416 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 417 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 418 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 419 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 420 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 421 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | /** The singleton instance. */ |
| 423 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 424 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 426 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 427 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 428 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 429 | private final CallManager mCM; |
| 430 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 431 | |
| 432 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 433 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 434 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 435 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 436 | private final SharedPreferences mTelephonySharedPreferences; |
| 437 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 438 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 439 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 440 | private PackageManager mPackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 442 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 443 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 444 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 445 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 446 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 447 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 448 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 449 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 450 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 451 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 452 | // String to store multi SIM allowed |
| 453 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 454 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 455 | // The AID of ISD-R. |
| 456 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 457 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 458 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 459 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 460 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 461 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 462 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 463 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 464 | 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] | 465 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 466 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 467 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 468 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 469 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 470 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 471 | */ |
| 472 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 473 | "reset_network_erase_modem_config_enabled"; |
| 474 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 475 | 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] | 476 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 477 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 478 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 479 | /** |
| 480 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 481 | * one ICCID active at the same time. |
| 482 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 483 | * |
| 484 | * @hide |
| 485 | */ |
| 486 | @ChangeId |
| 487 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 488 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 489 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 490 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 491 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 492 | * operation fails. |
| 493 | */ |
| 494 | @ChangeId |
| 495 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 496 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 497 | |
| 498 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 499 | * A request object to use for transmitting data to an ICC. |
| 500 | */ |
| 501 | private static final class IccAPDUArgument { |
| 502 | public int channel, cla, command, p1, p2, p3; |
| 503 | public String data; |
| 504 | |
| 505 | public IccAPDUArgument(int channel, int cla, int command, |
| 506 | int p1, int p2, int p3, String data) { |
| 507 | this.channel = channel; |
| 508 | this.cla = cla; |
| 509 | this.command = command; |
| 510 | this.p1 = p1; |
| 511 | this.p2 = p2; |
| 512 | this.p3 = p3; |
| 513 | this.data = data; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 518 | * A request object to use for transmitting data to an ICC. |
| 519 | */ |
| 520 | private static final class ManualNetworkSelectionArgument { |
| 521 | public OperatorInfo operatorInfo; |
| 522 | public boolean persistSelection; |
| 523 | |
| 524 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 525 | this.operatorInfo = operatorInfo; |
| 526 | this.persistSelection = persistSelection; |
| 527 | } |
| 528 | } |
| 529 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 530 | private static final class PurchasePremiumCapabilityArgument { |
| 531 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 532 | public @NonNull IIntegerConsumer callback; |
| 533 | |
| 534 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 535 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 536 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 537 | this.callback = callback; |
| 538 | } |
| 539 | } |
| 540 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 541 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 543 | * request after sending. The main thread will notify the request when it is complete. |
| 544 | */ |
| 545 | private static final class MainThreadRequest { |
| 546 | /** The argument to use for the request */ |
| 547 | public Object argument; |
| 548 | /** The result of the request that is run on the main thread */ |
| 549 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 550 | // The subscriber id that this request applies to. Defaults to |
| 551 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 552 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 553 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 554 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 555 | public Phone phone; |
| 556 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 557 | public WorkSource workSource; |
| 558 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 559 | public MainThreadRequest(Object argument) { |
| 560 | this.argument = argument; |
| 561 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 562 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 563 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 564 | this.argument = argument; |
| 565 | if (phone != null) { |
| 566 | this.phone = phone; |
| 567 | } |
| 568 | this.workSource = workSource; |
| 569 | } |
| 570 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 571 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 572 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 573 | if (subId != null) { |
| 574 | this.subId = subId; |
| 575 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 576 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 577 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 580 | private static final class IncomingThirdPartyCallArgs { |
| 581 | public final ComponentName component; |
| 582 | public final String callId; |
| 583 | public final String callerDisplayName; |
| 584 | |
| 585 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 586 | String callerDisplayName) { |
| 587 | this.component = component; |
| 588 | this.callId = callId; |
| 589 | this.callerDisplayName = callerDisplayName; |
| 590 | } |
| 591 | } |
| 592 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 593 | /** |
| 594 | * A handler that processes messages on the main thread in the phone process. Since many |
| 595 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 596 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 597 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 598 | * on, which will be notified when the operation completes and will contain the result of the |
| 599 | * request. |
| 600 | * |
| 601 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 602 | * note that request.result must be set to something non-null for the calling thread to |
| 603 | * unblock. |
| 604 | */ |
| 605 | private final class MainThreadHandler extends Handler { |
| 606 | @Override |
| 607 | public void handleMessage(Message msg) { |
| 608 | MainThreadRequest request; |
| 609 | Message onCompleted; |
| 610 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 611 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 613 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 614 | |
| 615 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | case CMD_HANDLE_USSD_REQUEST: { |
| 617 | request = (MainThreadRequest) msg.obj; |
| 618 | final Phone phone = getPhoneFromRequest(request); |
| 619 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 620 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 622 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 623 | if (!isUssdApiAllowed(request.subId)) { |
| 624 | // Carrier does not support use of this API, return failure. |
| 625 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 626 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 627 | Bundle returnData = new Bundle(); |
| 628 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 629 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 630 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 631 | request.result = true; |
| 632 | notifyRequester(request); |
| 633 | return; |
| 634 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 635 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 636 | try { |
| 637 | request.result = phone != null |
| 638 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 639 | } catch (CallStateException cse) { |
| 640 | request.result = false; |
| 641 | } |
| 642 | // Wake up the requesting thread |
| 643 | notifyRequester(request); |
| 644 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 647 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 648 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 649 | final Phone phone = getPhoneFromRequest(request); |
| 650 | request.result = phone != null ? |
| 651 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 652 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 653 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 654 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 655 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 657 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 660 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 661 | uiccPort = getUiccPortFromRequest(request); |
| 662 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 664 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 665 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 666 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 668 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 669 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 670 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 671 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 672 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 673 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | break; |
| 675 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 676 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | ar = (AsyncResult) msg.obj; |
| 678 | request = (MainThreadRequest) ar.userObj; |
| 679 | if (ar.exception == null && ar.result != null) { |
| 680 | request.result = ar.result; |
| 681 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | if (ar.result == null) { |
| 684 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 685 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | } else { |
| 689 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 690 | } |
| 691 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 692 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | break; |
| 694 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 696 | request = (MainThreadRequest) msg.obj; |
| 697 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 698 | uiccPort = getUiccPortFromRequest(request); |
| 699 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 700 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 701 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 702 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | } else { |
| 704 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 705 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 706 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 707 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 708 | iccArgument.p2, |
| 709 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 710 | } |
| 711 | break; |
| 712 | |
| 713 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 714 | ar = (AsyncResult) msg.obj; |
| 715 | request = (MainThreadRequest) ar.userObj; |
| 716 | if (ar.exception == null && ar.result != null) { |
| 717 | request.result = ar.result; |
| 718 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 719 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 720 | if (ar.result == null) { |
| 721 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 722 | } else if (ar.exception instanceof CommandException) { |
| 723 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 724 | ar.exception); |
| 725 | } else { |
| 726 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 727 | } |
| 728 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 729 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case CMD_EXCHANGE_SIM_IO: |
| 733 | request = (MainThreadRequest) msg.obj; |
| 734 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 735 | uiccPort = getUiccPortFromRequest(request); |
| 736 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 737 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 738 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 739 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 740 | } else { |
| 741 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 742 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 743 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 744 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 745 | iccArgument.data, onCompleted); |
| 746 | } |
| 747 | break; |
| 748 | |
| 749 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 750 | ar = (AsyncResult) msg.obj; |
| 751 | request = (MainThreadRequest) ar.userObj; |
| 752 | if (ar.exception == null && ar.result != null) { |
| 753 | request.result = ar.result; |
| 754 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 755 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 756 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 757 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 758 | break; |
| 759 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 760 | case CMD_SEND_ENVELOPE: |
| 761 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 762 | uiccPort = getUiccPortFromRequest(request); |
| 763 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 764 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 765 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 767 | } else { |
| 768 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 769 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 770 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_SEND_ENVELOPE_DONE: |
| 774 | ar = (AsyncResult) msg.obj; |
| 775 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 776 | if (ar.exception == null && ar.result != null) { |
| 777 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 778 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 779 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 780 | if (ar.result == null) { |
| 781 | loge("sendEnvelopeWithStatus: Empty response"); |
| 782 | } else if (ar.exception instanceof CommandException) { |
| 783 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 784 | ar.exception); |
| 785 | } else { |
| 786 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 787 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 788 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 789 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 790 | break; |
| 791 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | case CMD_OPEN_CHANNEL: |
| 793 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 794 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 795 | IccLogicalChannelRequest openChannelRequest = |
| 796 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 797 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 798 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 799 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 800 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 801 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 802 | } else { |
| 803 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 804 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 805 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 806 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 807 | break; |
| 808 | |
| 809 | case EVENT_OPEN_CHANNEL_DONE: |
| 810 | ar = (AsyncResult) msg.obj; |
| 811 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 812 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 813 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 814 | int[] result = (int[]) ar.result; |
| 815 | int channelId = result[0]; |
| 816 | byte[] selectResponse = null; |
| 817 | if (result.length > 1) { |
| 818 | selectResponse = new byte[result.length - 1]; |
| 819 | for (int i = 1; i < result.length; ++i) { |
| 820 | selectResponse[i - 1] = (byte) result[i]; |
| 821 | } |
| 822 | } |
| 823 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 824 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 825 | |
| 826 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 827 | if (uiccPort == null) { |
| 828 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 829 | } else { |
| 830 | IccLogicalChannelRequest channelRequest = |
| 831 | (IccLogicalChannelRequest) request.argument; |
| 832 | channelRequest.channel = channelId; |
| 833 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 834 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 835 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 836 | if (ar.result == null) { |
| 837 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 838 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 839 | if (ar.exception != null) { |
| 840 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 841 | } |
| 842 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 843 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 844 | if (ar.exception instanceof CommandException) { |
| 845 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 846 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 847 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 848 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 849 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 850 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 854 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 855 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 856 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 857 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
| 860 | case CMD_CLOSE_CHANNEL: |
| 861 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 862 | uiccPort = getUiccPortFromRequest(request); |
| 863 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 864 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 865 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 866 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 867 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 868 | } else { |
| 869 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 870 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 871 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 875 | ar = (AsyncResult) msg.obj; |
| 876 | request = (MainThreadRequest) ar.userObj; |
| 877 | if (ar.exception == null) { |
| 878 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 879 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 880 | if (uiccPort == null) { |
| 881 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 882 | } else { |
| 883 | final int channelId = (Integer) request.argument; |
| 884 | uiccPort.onLogicalChannelClosed(channelId); |
| 885 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 886 | } else { |
| 887 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 888 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 889 | if (ar.exception instanceof CommandException) { |
| 890 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 891 | CommandException.Error error = |
| 892 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 893 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 894 | // should only throw exceptions from the binder threads. |
| 895 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 896 | "iccCloseLogicalChannel: invalid argument "); |
| 897 | } |
| 898 | } else { |
| 899 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 900 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 901 | request.result = (exception != null) ? exception : |
| 902 | new IllegalStateException( |
| 903 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 904 | } |
| 905 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case CMD_NV_READ_ITEM: |
| 909 | request = (MainThreadRequest) msg.obj; |
| 910 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 911 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 912 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 913 | break; |
| 914 | |
| 915 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 916 | ar = (AsyncResult) msg.obj; |
| 917 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 918 | if (ar.exception == null && ar.result != null) { |
| 919 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 920 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 921 | request.result = ""; |
| 922 | if (ar.result == null) { |
| 923 | loge("nvReadItem: Empty response"); |
| 924 | } else if (ar.exception instanceof CommandException) { |
| 925 | loge("nvReadItem: CommandException: " + |
| 926 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 927 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 928 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 929 | } |
| 930 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 931 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 932 | break; |
| 933 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 934 | case CMD_NV_WRITE_ITEM: |
| 935 | request = (MainThreadRequest) msg.obj; |
| 936 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 937 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 938 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 939 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 940 | break; |
| 941 | |
| 942 | case EVENT_NV_WRITE_ITEM_DONE: |
| 943 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 944 | break; |
| 945 | |
| 946 | case CMD_NV_WRITE_CDMA_PRL: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 949 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 950 | break; |
| 951 | |
| 952 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 953 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 954 | break; |
| 955 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 956 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 957 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 958 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 959 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 960 | break; |
| 961 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 962 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 963 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 964 | break; |
| 965 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 966 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 967 | request = (MainThreadRequest) msg.obj; |
| 968 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 969 | request); |
| 970 | Phone phone = getPhoneFromRequest(request); |
| 971 | if (phone != null) { |
| 972 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 973 | } else { |
| 974 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 975 | request.result = false; |
| 976 | notifyRequester(request); |
| 977 | } |
| 978 | break; |
| 979 | } |
| 980 | |
| 981 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 982 | ar = (AsyncResult) msg.obj; |
| 983 | request = (MainThreadRequest) ar.userObj; |
| 984 | if (ar.exception == null && ar.result != null) { |
| 985 | request.result = ar.result; |
| 986 | } else { |
| 987 | // request.result must be set to something non-null |
| 988 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 989 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 990 | request.result = ar.result; |
| 991 | } else { |
| 992 | request.result = false; |
| 993 | } |
| 994 | if (ar.result == null) { |
| 995 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 996 | } else if (ar.exception instanceof CommandException) { |
| 997 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 998 | + ar.exception); |
| 999 | } else { |
| 1000 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1001 | } |
| 1002 | } |
| 1003 | notifyRequester(request); |
| 1004 | break; |
| 1005 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1006 | case CMD_IS_VONR_ENABLED: { |
| 1007 | request = (MainThreadRequest) msg.obj; |
| 1008 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1009 | request); |
| 1010 | Phone phone = getPhoneFromRequest(request); |
| 1011 | if (phone != null) { |
| 1012 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1013 | } else { |
| 1014 | loge("isVoNrEnabled: No phone object"); |
| 1015 | request.result = false; |
| 1016 | notifyRequester(request); |
| 1017 | } |
| 1018 | break; |
| 1019 | } |
| 1020 | |
| 1021 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1022 | ar = (AsyncResult) msg.obj; |
| 1023 | request = (MainThreadRequest) ar.userObj; |
| 1024 | if (ar.exception == null && ar.result != null) { |
| 1025 | request.result = ar.result; |
| 1026 | } else { |
| 1027 | // request.result must be set to something non-null |
| 1028 | // for the calling thread to unblock |
| 1029 | if (ar.result != null) { |
| 1030 | request.result = ar.result; |
| 1031 | } else { |
| 1032 | request.result = false; |
| 1033 | } |
| 1034 | if (ar.result == null) { |
| 1035 | loge("isVoNrEnabled: Empty response"); |
| 1036 | } else if (ar.exception instanceof CommandException) { |
| 1037 | loge("isVoNrEnabled: CommandException: " |
| 1038 | + ar.exception); |
| 1039 | } else { |
| 1040 | loge("isVoNrEnabled: Unknown exception"); |
| 1041 | } |
| 1042 | } |
| 1043 | notifyRequester(request); |
| 1044 | break; |
| 1045 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1046 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1047 | request = (MainThreadRequest) msg.obj; |
| 1048 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1049 | Phone phone = getPhoneFromRequest(request); |
| 1050 | if (phone != null) { |
| 1051 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1052 | request.workSource); |
| 1053 | } else { |
| 1054 | loge("enableNrDualConnectivity: No phone object"); |
| 1055 | request.result = |
| 1056 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1057 | notifyRequester(request); |
| 1058 | } |
| 1059 | break; |
| 1060 | } |
| 1061 | |
| 1062 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1063 | ar = (AsyncResult) msg.obj; |
| 1064 | request = (MainThreadRequest) ar.userObj; |
| 1065 | if (ar.exception == null) { |
| 1066 | request.result = |
| 1067 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1068 | } else { |
| 1069 | request.result = |
| 1070 | TelephonyManager |
| 1071 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1072 | if (ar.exception instanceof CommandException) { |
| 1073 | CommandException.Error error = |
| 1074 | ((CommandException) (ar.exception)).getCommandError(); |
| 1075 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1076 | request.result = |
| 1077 | TelephonyManager |
| 1078 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1079 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1080 | request.result = |
| 1081 | TelephonyManager |
| 1082 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1083 | } |
| 1084 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1085 | + ar.exception); |
| 1086 | } else { |
| 1087 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1088 | } |
| 1089 | } |
| 1090 | notifyRequester(request); |
| 1091 | break; |
| 1092 | } |
| 1093 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1094 | case CMD_ENABLE_VONR: { |
| 1095 | request = (MainThreadRequest) msg.obj; |
| 1096 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1097 | Phone phone = getPhoneFromRequest(request); |
| 1098 | if (phone != null) { |
| 1099 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1100 | request.workSource); |
| 1101 | } else { |
| 1102 | loge("setVoNrEnabled: No phone object"); |
| 1103 | request.result = |
| 1104 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1105 | notifyRequester(request); |
| 1106 | } |
| 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | case EVENT_ENABLE_VONR_DONE: { |
| 1111 | ar = (AsyncResult) msg.obj; |
| 1112 | request = (MainThreadRequest) ar.userObj; |
| 1113 | if (ar.exception == null) { |
| 1114 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1115 | } else { |
| 1116 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1117 | if (ar.exception instanceof CommandException) { |
| 1118 | CommandException.Error error = |
| 1119 | ((CommandException) (ar.exception)).getCommandError(); |
| 1120 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1121 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1122 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1123 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1124 | } else { |
| 1125 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1126 | } |
| 1127 | loge("setVoNrEnabled" + ": CommandException: " |
| 1128 | + ar.exception); |
| 1129 | } else { |
| 1130 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1131 | } |
| 1132 | } |
| 1133 | notifyRequester(request); |
| 1134 | break; |
| 1135 | } |
| 1136 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1137 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1138 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1139 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1140 | request); |
| 1141 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1142 | break; |
| 1143 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1144 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1145 | ar = (AsyncResult) msg.obj; |
| 1146 | request = (MainThreadRequest) ar.userObj; |
| 1147 | if (ar.exception == null && ar.result != null) { |
| 1148 | request.result = ar.result; // Integer |
| 1149 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1150 | // request.result must be set to something non-null |
| 1151 | // for the calling thread to unblock |
| 1152 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1153 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1154 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1155 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1156 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1157 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1158 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1159 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1160 | } |
| 1161 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1162 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1163 | break; |
| 1164 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1165 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1166 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1167 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1168 | request); |
| 1169 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1170 | (Pair<Integer, Long>) request.argument; |
| 1171 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1172 | reasonWithNetworkTypes.first, |
| 1173 | reasonWithNetworkTypes.second, |
| 1174 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1175 | break; |
| 1176 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1177 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1178 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1179 | break; |
| 1180 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1181 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1182 | request = (MainThreadRequest) msg.obj; |
| 1183 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1184 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1185 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1186 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1187 | break; |
| 1188 | |
| 1189 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1190 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1191 | break; |
| 1192 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1193 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1194 | request = (MainThreadRequest) msg.obj; |
| 1195 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1196 | request); |
| 1197 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1198 | break; |
| 1199 | |
| 1200 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1201 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1202 | break; |
| 1203 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1204 | case CMD_PERFORM_NETWORK_SCAN: |
| 1205 | request = (MainThreadRequest) msg.obj; |
| 1206 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1207 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1208 | break; |
| 1209 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1210 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | request = (MainThreadRequest) msg.obj; |
| 1212 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1214 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1215 | request.argument; |
| 1216 | int callForwardingReason = args.first; |
| 1217 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | } |
| 1220 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | ar = (AsyncResult) msg.obj; |
| 1222 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1224 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1225 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1229 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1230 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1231 | // any service for voice call. |
| 1232 | if ((callForwardInfo.serviceClass |
| 1233 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1234 | callForwardingInfo = new CallForwardingInfo( |
| 1235 | callForwardInfo.status |
| 1236 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1237 | callForwardInfo.reason, |
| 1238 | callForwardInfo.number, |
| 1239 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1240 | break; |
| 1241 | } |
| 1242 | } |
| 1243 | // Didn't find a call forward info for voice call. |
| 1244 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1245 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1246 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | } else { |
| 1250 | if (ar.result == null) { |
| 1251 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1252 | } |
| 1253 | if (ar.exception != null) { |
| 1254 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1255 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1256 | int errorCode = TelephonyManager |
| 1257 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | if (ar.exception instanceof CommandException) { |
| 1259 | CommandException.Error error = |
| 1260 | ((CommandException) (ar.exception)).getCommandError(); |
| 1261 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1262 | errorCode = TelephonyManager |
| 1263 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1265 | errorCode = TelephonyManager |
| 1266 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | } |
| 1268 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | request = (MainThreadRequest) msg.obj; |
| 1276 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1280 | request.argument).first; |
| 1281 | request.phone.setCallForwardingOption( |
| 1282 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1283 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1285 | callForwardingInfoToSet.getReason(), |
| 1286 | callForwardingInfoToSet.getNumber(), |
| 1287 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1288 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1289 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1292 | ar = (AsyncResult) msg.obj; |
| 1293 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | Consumer<Integer> callback = |
| 1295 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1296 | request.argument).second; |
| 1297 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1298 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1299 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1300 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | if (ar.exception instanceof CommandException) { |
| 1302 | CommandException.Error error = |
| 1303 | ((CommandException) (ar.exception)).getCommandError(); |
| 1304 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1305 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1306 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1308 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1309 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | callback.accept(errorCode); |
| 1313 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1314 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1317 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1318 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1319 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1320 | request = (MainThreadRequest) msg.obj; |
| 1321 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1322 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1323 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1324 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1325 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1326 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1327 | ar = (AsyncResult) msg.obj; |
| 1328 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1329 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1330 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1332 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | // Service Class is a bit mask per 3gpp 27.007. |
| 1334 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1335 | if (callForwardResults.length > 1 |
| 1336 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1337 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1338 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1340 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1342 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | } |
| 1344 | } else { |
| 1345 | if (ar.result == null) { |
| 1346 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1347 | } |
| 1348 | if (ar.exception != null) { |
| 1349 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1350 | } |
| 1351 | if (ar.exception instanceof CommandException) { |
| 1352 | CommandException.Error error = |
| 1353 | ((CommandException) (ar.exception)).getCommandError(); |
| 1354 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1355 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1357 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1358 | callWaitingStatus = |
| 1359 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1363 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1365 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1366 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1367 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1368 | request = (MainThreadRequest) msg.obj; |
| 1369 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1370 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1371 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1373 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1375 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1376 | ar = (AsyncResult) msg.obj; |
| 1377 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1378 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1379 | Consumer<Integer> callback = |
| 1380 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1381 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1382 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1383 | if (ar.exception instanceof CommandException) { |
| 1384 | CommandException.Error error = |
| 1385 | ((CommandException) (ar.exception)).getCommandError(); |
| 1386 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1387 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1388 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1389 | callback.accept( |
| 1390 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1391 | } else { |
| 1392 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1393 | } |
| 1394 | } else { |
| 1395 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1396 | } |
| 1397 | } else { |
| 1398 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1399 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1400 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1401 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1402 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1403 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1404 | ar = (AsyncResult) msg.obj; |
| 1405 | request = (MainThreadRequest) ar.userObj; |
| 1406 | CellNetworkScanResult cellScanResult; |
| 1407 | if (ar.exception == null && ar.result != null) { |
| 1408 | cellScanResult = new CellNetworkScanResult( |
| 1409 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1410 | (List<OperatorInfo>) ar.result); |
| 1411 | } else { |
| 1412 | if (ar.result == null) { |
| 1413 | loge("getCellNetworkScanResults: Empty response"); |
| 1414 | } |
| 1415 | if (ar.exception != null) { |
| 1416 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1417 | } |
| 1418 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1419 | if (ar.exception instanceof CommandException) { |
| 1420 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1421 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1422 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1423 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1424 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1425 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1426 | } |
| 1427 | } |
| 1428 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1429 | } |
| 1430 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1431 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1432 | break; |
| 1433 | |
| 1434 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1435 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1436 | ManualNetworkSelectionArgument selArg = |
| 1437 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1438 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1439 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1440 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1441 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1442 | break; |
| 1443 | |
| 1444 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1445 | ar = (AsyncResult) msg.obj; |
| 1446 | request = (MainThreadRequest) ar.userObj; |
| 1447 | if (ar.exception == null) { |
| 1448 | request.result = true; |
| 1449 | } else { |
| 1450 | request.result = false; |
| 1451 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1452 | } |
| 1453 | notifyRequester(request); |
| 1454 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1455 | break; |
| 1456 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1457 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1458 | request = (MainThreadRequest) msg.obj; |
| 1459 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1460 | if (defaultPhone != null) { |
| 1461 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1462 | } else { |
| 1463 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1464 | Bundle bundle = new Bundle(); |
| 1465 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1466 | new ModemActivityInfo(0, 0, 0, |
| 1467 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1468 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1469 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1470 | break; |
| 1471 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1472 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1473 | ar = (AsyncResult) msg.obj; |
| 1474 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1475 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1476 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1477 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1478 | if (mLastModemActivityInfo == null) { |
| 1479 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1480 | mLastModemActivitySpecificInfo[0] = |
| 1481 | new ActivityStatsTechSpecificInfo( |
| 1482 | 0, |
| 1483 | 0, |
| 1484 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1485 | 0); |
| 1486 | mLastModemActivityInfo = |
| 1487 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1488 | } |
| 1489 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1490 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1491 | // Update the last modem activity info and the result of the request. |
| 1492 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1493 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1494 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1495 | } else { |
| 1496 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1497 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1498 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1499 | // We don't want to return mLastModemActivityInfo which is updated |
| 1500 | // inside mergeModemActivityInfo() |
| 1501 | ret = new ModemActivityInfo( |
| 1502 | mLastModemActivityInfo.getTimestampMillis(), |
| 1503 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1504 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1505 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1506 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1507 | } else { |
| 1508 | if (ar.result == null) { |
| 1509 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1510 | error = TelephonyManager.ModemActivityInfoException |
| 1511 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1512 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1513 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1514 | error = TelephonyManager.ModemActivityInfoException |
| 1515 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1516 | } else { |
| 1517 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1518 | error = TelephonyManager.ModemActivityInfoException |
| 1519 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1520 | } |
| 1521 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1522 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1523 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1524 | bundle.putParcelable( |
| 1525 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1526 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1527 | } else { |
| 1528 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1529 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1530 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1531 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1532 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1533 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1534 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1535 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1536 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1537 | CarrierRestrictionRules argument = |
| 1538 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1539 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1540 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1541 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1542 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1543 | |
| 1544 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1545 | ar = (AsyncResult) msg.obj; |
| 1546 | request = (MainThreadRequest) ar.userObj; |
| 1547 | if (ar.exception == null && ar.result != null) { |
| 1548 | request.result = ar.result; |
| 1549 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1550 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1551 | if (ar.exception instanceof CommandException) { |
| 1552 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1553 | CommandException.Error error = |
| 1554 | ((CommandException) (ar.exception)).getCommandError(); |
| 1555 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1556 | request.result = |
| 1557 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1558 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1559 | } else { |
| 1560 | loge("setAllowedCarriers: Unknown exception"); |
| 1561 | } |
| 1562 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1563 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1564 | break; |
| 1565 | |
| 1566 | case CMD_GET_ALLOWED_CARRIERS: |
| 1567 | request = (MainThreadRequest) msg.obj; |
| 1568 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1569 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1570 | break; |
| 1571 | |
| 1572 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1573 | ar = (AsyncResult) msg.obj; |
| 1574 | request = (MainThreadRequest) ar.userObj; |
| 1575 | if (ar.exception == null && ar.result != null) { |
| 1576 | request.result = ar.result; |
| 1577 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1578 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1579 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1580 | if (ar.result == null) { |
| 1581 | loge("getAllowedCarriers: Empty response"); |
| 1582 | } else if (ar.exception instanceof CommandException) { |
| 1583 | loge("getAllowedCarriers: CommandException: " + |
| 1584 | ar.exception); |
| 1585 | } else { |
| 1586 | loge("getAllowedCarriers: Unknown exception"); |
| 1587 | } |
| 1588 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1589 | if (request.argument != null) { |
| 1590 | // This is for the implementation of carrierRestrictionStatus. |
| 1591 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1592 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1593 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1594 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1595 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1596 | CarrierRestrictionRules carrierRestrictionRules = |
| 1597 | (CarrierRestrictionRules) ar.result; |
| 1598 | int carrierId = -1; |
| 1599 | try { |
| 1600 | CarrierIdentifier carrierIdentifier = |
| 1601 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1602 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1603 | carrierIdentifier); |
| 1604 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1605 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1606 | } |
| 1607 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1608 | int restrictedStatus = |
| 1609 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1610 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1611 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1612 | lockStatus = TelephonyManager |
| 1613 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1614 | } |
| 1615 | } else { |
| 1616 | Rlog.e(LOG_TAG, |
| 1617 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1618 | } |
| 1619 | callback.accept(lockStatus); |
| 1620 | } else { |
| 1621 | // This is for the implementation of getAllowedCarriers. |
| 1622 | notifyRequester(request); |
| 1623 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1624 | break; |
| 1625 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1626 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1627 | ar = (AsyncResult) msg.obj; |
| 1628 | request = (MainThreadRequest) ar.userObj; |
| 1629 | if (ar.exception == null && ar.result != null) { |
| 1630 | request.result = ar.result; |
| 1631 | } else { |
| 1632 | request.result = new IllegalArgumentException( |
| 1633 | "Failed to retrieve Forbidden Plmns"); |
| 1634 | if (ar.result == null) { |
| 1635 | loge("getForbiddenPlmns: Empty response"); |
| 1636 | } else { |
| 1637 | loge("getForbiddenPlmns: Unknown exception"); |
| 1638 | } |
| 1639 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1640 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1641 | break; |
| 1642 | |
| 1643 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1644 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1645 | uiccPort = getUiccPortFromRequest(request); |
| 1646 | if (uiccPort == null) { |
| 1647 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1648 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1649 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1650 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1651 | break; |
| 1652 | } |
| 1653 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1654 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1655 | if (uiccApp == null) { |
| 1656 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1657 | + appType); |
| 1658 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1659 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1660 | break; |
| 1661 | } else { |
| 1662 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1663 | + " specified type -- " + appType); |
| 1664 | } |
| 1665 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1666 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1667 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1668 | break; |
| 1669 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1670 | case CMD_SWITCH_SLOTS: |
| 1671 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1672 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1673 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1674 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1675 | break; |
| 1676 | |
| 1677 | case EVENT_SWITCH_SLOTS_DONE: |
| 1678 | ar = (AsyncResult) msg.obj; |
| 1679 | request = (MainThreadRequest) ar.userObj; |
| 1680 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1681 | notifyRequester(request); |
| 1682 | break; |
| 1683 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1684 | request = (MainThreadRequest) msg.obj; |
| 1685 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1686 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1687 | break; |
| 1688 | |
| 1689 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1690 | ar = (AsyncResult) msg.obj; |
| 1691 | request = (MainThreadRequest) ar.userObj; |
| 1692 | if (ar.exception != null) { |
| 1693 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1694 | } else { |
| 1695 | int mode = ((int[]) ar.result)[0]; |
| 1696 | if (mode == 0) { |
| 1697 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1698 | } else { |
| 1699 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1700 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1701 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1702 | notifyRequester(request); |
| 1703 | break; |
| 1704 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1705 | request = (MainThreadRequest) msg.obj; |
| 1706 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1707 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1708 | break; |
| 1709 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1710 | ar = (AsyncResult) msg.obj; |
| 1711 | request = (MainThreadRequest) ar.userObj; |
| 1712 | if (ar.exception != null) { |
| 1713 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1714 | } else { |
| 1715 | request.result = ((int[]) ar.result)[0]; |
| 1716 | } |
| 1717 | notifyRequester(request); |
| 1718 | break; |
| 1719 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1720 | request = (MainThreadRequest) msg.obj; |
| 1721 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1722 | int mode = (int) request.argument; |
| 1723 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1724 | break; |
| 1725 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1726 | ar = (AsyncResult) msg.obj; |
| 1727 | request = (MainThreadRequest) ar.userObj; |
| 1728 | request.result = ar.exception == null; |
| 1729 | notifyRequester(request); |
| 1730 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1731 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1732 | request = (MainThreadRequest) msg.obj; |
| 1733 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1734 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1735 | break; |
| 1736 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1737 | ar = (AsyncResult) msg.obj; |
| 1738 | request = (MainThreadRequest) ar.userObj; |
| 1739 | if (ar.exception != null) { |
| 1740 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1741 | } else { |
| 1742 | request.result = ((int[]) ar.result)[0]; |
| 1743 | } |
| 1744 | notifyRequester(request); |
| 1745 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1746 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1747 | request = (MainThreadRequest) msg.obj; |
| 1748 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1749 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1750 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1751 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1752 | break; |
| 1753 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1754 | ar = (AsyncResult) msg.obj; |
| 1755 | request = (MainThreadRequest) ar.userObj; |
| 1756 | request.result = ar.exception == null; |
| 1757 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1758 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1759 | case CMD_GET_ALL_CELL_INFO: |
| 1760 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1761 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1762 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1763 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1764 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1765 | ar = (AsyncResult) msg.obj; |
| 1766 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1767 | // If a timeout occurs, the response will be null |
| 1768 | request.result = (ar.exception == null && ar.result != null) |
| 1769 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1770 | synchronized (request) { |
| 1771 | request.notifyAll(); |
| 1772 | } |
| 1773 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1774 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1775 | request = (MainThreadRequest) msg.obj; |
| 1776 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1777 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1778 | break; |
| 1779 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1780 | ar = (AsyncResult) msg.obj; |
| 1781 | request = (MainThreadRequest) ar.userObj; |
| 1782 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1783 | try { |
| 1784 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1785 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1786 | cb.onError( |
| 1787 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1788 | ar.exception.getClass().getName(), |
| 1789 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1790 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1791 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1792 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1793 | } else { |
| 1794 | // use the result as returned |
| 1795 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1796 | } |
| 1797 | } catch (RemoteException re) { |
| 1798 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1799 | } |
| 1800 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1801 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1802 | request = (MainThreadRequest) msg.obj; |
| 1803 | WorkSource ws = (WorkSource) request.argument; |
| 1804 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1805 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1806 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1807 | } |
| 1808 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1809 | ar = (AsyncResult) msg.obj; |
| 1810 | request = (MainThreadRequest) ar.userObj; |
| 1811 | if (ar.exception == null) { |
| 1812 | request.result = ar.result; |
| 1813 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1814 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1815 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1816 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | synchronized (request) { |
| 1820 | request.notifyAll(); |
| 1821 | } |
| 1822 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1823 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1824 | case CMD_MODEM_REBOOT: |
| 1825 | request = (MainThreadRequest) msg.obj; |
| 1826 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1827 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1828 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1829 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1830 | handleNullReturnEvent(msg, "rebootModem"); |
| 1831 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1832 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1833 | request = (MainThreadRequest) msg.obj; |
| 1834 | boolean enable = (boolean) request.argument; |
| 1835 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1836 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1837 | PhoneConfigurationManager.getInstance() |
| 1838 | .enablePhone(request.phone, enable, onCompleted); |
| 1839 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1840 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1841 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1842 | ar = (AsyncResult) msg.obj; |
| 1843 | request = (MainThreadRequest) ar.userObj; |
| 1844 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1845 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1846 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1847 | if ((boolean) request.result) { |
| 1848 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1849 | updateModemStateMetrics(); |
| 1850 | } else { |
| 1851 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1852 | + ar.exception); |
| 1853 | } |
| 1854 | notifyRequester(request); |
| 1855 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1856 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1857 | case CMD_GET_MODEM_STATUS: |
| 1858 | request = (MainThreadRequest) msg.obj; |
| 1859 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1860 | PhoneConfigurationManager.getInstance() |
| 1861 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1862 | break; |
| 1863 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1864 | ar = (AsyncResult) msg.obj; |
| 1865 | request = (MainThreadRequest) ar.userObj; |
| 1866 | int id = request.phone.getPhoneId(); |
| 1867 | if (ar.exception == null && ar.result != null) { |
| 1868 | request.result = ar.result; |
| 1869 | //update the cache as modem status has changed |
| 1870 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1871 | (boolean) request.result); |
| 1872 | } else { |
| 1873 | // Return true if modem status cannot be retrieved. For most cases, |
| 1874 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1875 | // and disable modem are not supported. Modem is always on. |
| 1876 | // TODO: this should be fixed in R to support a third |
| 1877 | // status UNKNOWN b/131631629 |
| 1878 | request.result = true; |
| 1879 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1880 | + ar.exception); |
| 1881 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1882 | notifyRequester(request); |
| 1883 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1884 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1885 | request = (MainThreadRequest) msg.obj; |
| 1886 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1887 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1888 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1889 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1890 | break; |
| 1891 | } |
| 1892 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1893 | ar = (AsyncResult) msg.obj; |
| 1894 | request = (MainThreadRequest) ar.userObj; |
| 1895 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1896 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1897 | args.second.accept(ar.exception == null); |
| 1898 | notifyRequester(request); |
| 1899 | break; |
| 1900 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1901 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1902 | request = (MainThreadRequest) msg.obj; |
| 1903 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1904 | Phone phone = getPhoneFromRequest(request); |
| 1905 | if (phone != null) { |
| 1906 | phone.getSystemSelectionChannels(onCompleted); |
| 1907 | } else { |
| 1908 | loge("getSystemSelectionChannels: No phone object"); |
| 1909 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1910 | notifyRequester(request); |
| 1911 | } |
| 1912 | break; |
| 1913 | } |
| 1914 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1915 | ar = (AsyncResult) msg.obj; |
| 1916 | request = (MainThreadRequest) ar.userObj; |
| 1917 | if (ar.exception == null && ar.result != null) { |
| 1918 | request.result = ar.result; |
| 1919 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1920 | request.result = new IllegalStateException( |
| 1921 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1922 | if (ar.result == null) { |
| 1923 | loge("getSystemSelectionChannels: Empty response"); |
| 1924 | } else { |
| 1925 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1926 | } |
| 1927 | } |
| 1928 | notifyRequester(request); |
| 1929 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1930 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1931 | ar = (AsyncResult) msg.obj; |
| 1932 | request = (MainThreadRequest) ar.userObj; |
| 1933 | if (ar.exception == null && ar.result != null) { |
| 1934 | request.result = ar.result; |
| 1935 | } else { |
| 1936 | request.result = -1; |
| 1937 | loge("Failed to set Forbidden Plmns"); |
| 1938 | if (ar.result == null) { |
| 1939 | loge("setForbidenPlmns: Empty response"); |
| 1940 | } else if (ar.exception != null) { |
| 1941 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1942 | request.result = -1; |
| 1943 | } else { |
| 1944 | loge("setForbiddenPlmns: Unknown exception"); |
| 1945 | } |
| 1946 | } |
| 1947 | notifyRequester(request); |
| 1948 | break; |
| 1949 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1950 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1951 | uiccPort = getUiccPortFromRequest(request); |
| 1952 | if (uiccPort == null) { |
| 1953 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1954 | request.result = -1; |
| 1955 | notifyRequester(request); |
| 1956 | break; |
| 1957 | } |
| 1958 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1959 | (Pair<Integer, List<String>>) request.argument; |
| 1960 | appType = setFplmnsArgs.first; |
| 1961 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1962 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1963 | if (uiccApp == null) { |
| 1964 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1965 | request.result = -1; |
| 1966 | loge("Failed to get UICC App"); |
| 1967 | notifyRequester(request); |
| 1968 | } else { |
| 1969 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1970 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1971 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1972 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1973 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1974 | case CMD_ERASE_MODEM_CONFIG: |
| 1975 | request = (MainThreadRequest) msg.obj; |
| 1976 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1977 | defaultPhone.eraseModemConfig(onCompleted); |
| 1978 | break; |
| 1979 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1980 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1981 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1982 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1983 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1984 | request = (MainThreadRequest) msg.obj; |
| 1985 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1986 | notifyRequester(request); |
| 1987 | break; |
| 1988 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1989 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1990 | request = (MainThreadRequest) msg.obj; |
| 1991 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1992 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1993 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1994 | changed.first, changed.second, onCompleted); |
| 1995 | break; |
| 1996 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1997 | ar = (AsyncResult) msg.obj; |
| 1998 | request = (MainThreadRequest) ar.userObj; |
| 1999 | if (ar.exception == null) { |
| 2000 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2001 | // If the operation is successful, update the PIN storage |
| 2002 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2003 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2004 | UiccController.getInstance().getPinStorage() |
| 2005 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2006 | } else { |
| 2007 | request.result = msg.arg1; |
| 2008 | } |
| 2009 | notifyRequester(request); |
| 2010 | break; |
| 2011 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2012 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2013 | request = (MainThreadRequest) msg.obj; |
| 2014 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2015 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2016 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2017 | enabled.first, enabled.second, onCompleted); |
| 2018 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2019 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2020 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2021 | ar = (AsyncResult) msg.obj; |
| 2022 | request = (MainThreadRequest) ar.userObj; |
| 2023 | if (ar.exception == null) { |
| 2024 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2025 | // If the operation is successful, update the PIN storage |
| 2026 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2027 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2028 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2029 | UiccController.getInstance().getPinStorage() |
| 2030 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2031 | } else { |
| 2032 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2033 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2034 | } else { |
| 2035 | request.result = msg.arg1; |
| 2036 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2037 | |
| 2038 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2039 | notifyRequester(request); |
| 2040 | break; |
| 2041 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2042 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2043 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2044 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2045 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2046 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2047 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2048 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2049 | |
| 2050 | case CMD_SET_DATA_THROTTLING: { |
| 2051 | request = (MainThreadRequest) msg.obj; |
| 2052 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2053 | DataThrottlingRequest dataThrottlingRequest = |
| 2054 | (DataThrottlingRequest) request.argument; |
| 2055 | Phone phone = getPhoneFromRequest(request); |
| 2056 | if (phone != null) { |
| 2057 | phone.setDataThrottling(onCompleted, |
| 2058 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2059 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2060 | } else { |
| 2061 | loge("setDataThrottling: No phone object"); |
| 2062 | request.result = |
| 2063 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2064 | notifyRequester(request); |
| 2065 | } |
| 2066 | |
| 2067 | break; |
| 2068 | } |
| 2069 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2070 | ar = (AsyncResult) msg.obj; |
| 2071 | request = (MainThreadRequest) ar.userObj; |
| 2072 | |
| 2073 | if (ar.exception == null) { |
| 2074 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2075 | } else if (ar.exception instanceof CommandException) { |
| 2076 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2077 | CommandException.Error error = |
| 2078 | ((CommandException) (ar.exception)).getCommandError(); |
| 2079 | |
| 2080 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2081 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2082 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2083 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2084 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2085 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2086 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2087 | } else { |
| 2088 | request.result = |
| 2089 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2090 | } |
| 2091 | } else { |
| 2092 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2093 | } |
| 2094 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2095 | notifyRequester(request); |
| 2096 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2097 | |
| 2098 | case CMD_SET_SIM_POWER: { |
| 2099 | request = (MainThreadRequest) msg.obj; |
| 2100 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2101 | request = (MainThreadRequest) msg.obj; |
| 2102 | int stateToSet = |
| 2103 | ((Pair<Integer, IIntegerConsumer>) |
| 2104 | request.argument).first; |
| 2105 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2106 | break; |
| 2107 | } |
| 2108 | case EVENT_SET_SIM_POWER_DONE: { |
| 2109 | ar = (AsyncResult) msg.obj; |
| 2110 | request = (MainThreadRequest) ar.userObj; |
| 2111 | IIntegerConsumer callback = |
| 2112 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2113 | if (ar.exception != null) { |
| 2114 | loge("setSimPower exception: " + ar.exception); |
| 2115 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2116 | .RESULT_ERROR_UNKNOWN; |
| 2117 | if (ar.exception instanceof CommandException) { |
| 2118 | CommandException.Error error = |
| 2119 | ((CommandException) (ar.exception)).getCommandError(); |
| 2120 | if (error == CommandException.Error.SIM_ERR) { |
| 2121 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2122 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2123 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2124 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2125 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2126 | } else { |
| 2127 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2128 | } |
| 2129 | } |
| 2130 | try { |
| 2131 | callback.accept(errorCode); |
| 2132 | } catch (RemoteException e) { |
| 2133 | // Ignore if the remote process is no longer available to call back. |
| 2134 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2135 | } |
| 2136 | } else { |
| 2137 | try { |
| 2138 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2139 | } catch (RemoteException e) { |
| 2140 | // Ignore if the remote process is no longer available to call back. |
| 2141 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2142 | } |
| 2143 | } |
| 2144 | break; |
| 2145 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2146 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2147 | request = (MainThreadRequest) msg.obj; |
| 2148 | |
| 2149 | final Phone phone = getPhoneFromRequest(request); |
| 2150 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2151 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2152 | notifyRequester(request); |
| 2153 | break; |
| 2154 | } |
| 2155 | |
| 2156 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2157 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2158 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2159 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2160 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2161 | request.subId, pair.first /*callingUid*/, |
| 2162 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2163 | break; |
| 2164 | } |
| 2165 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2166 | ar = (AsyncResult) msg.obj; |
| 2167 | request = (MainThreadRequest) ar.userObj; |
| 2168 | // request.result will be the exception of ar if present, true otherwise. |
| 2169 | // Be cautious not to leave result null which will wait() forever |
| 2170 | request.result = ar.exception != null ? ar.exception : true; |
| 2171 | notifyRequester(request); |
| 2172 | break; |
| 2173 | } |
| 2174 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2175 | request = (MainThreadRequest) msg.obj; |
| 2176 | |
| 2177 | Phone phone = getPhoneFromRequest(request); |
| 2178 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2179 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2180 | notifyRequester(request); |
| 2181 | break; |
| 2182 | } |
| 2183 | |
| 2184 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2185 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2186 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2187 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2188 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2189 | request.subId, pair.first /*callingUid*/, |
| 2190 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2191 | break; |
| 2192 | } |
| 2193 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2194 | ar = (AsyncResult) msg.obj; |
| 2195 | request = (MainThreadRequest) ar.userObj; |
| 2196 | request.result = ar.exception != null ? ar.exception : true; |
| 2197 | notifyRequester(request); |
| 2198 | break; |
| 2199 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2200 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2201 | case CMD_GET_SLICING_CONFIG: { |
| 2202 | request = (MainThreadRequest) msg.obj; |
| 2203 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2204 | request.phone.getSlicingConfig(onCompleted); |
| 2205 | break; |
| 2206 | } |
| 2207 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2208 | ar = (AsyncResult) msg.obj; |
| 2209 | request = (MainThreadRequest) ar.userObj; |
| 2210 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2211 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2212 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2213 | Bundle bundle = new Bundle(); |
| 2214 | int resultCode = 0; |
| 2215 | if (ar.exception != null) { |
| 2216 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2217 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2218 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2219 | } else if (ar.result == null) { |
| 2220 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2221 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2222 | } else { |
| 2223 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2224 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2225 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2229 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2230 | } |
| 2231 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2232 | result.send(resultCode, bundle); |
| 2233 | notifyRequester(request); |
| 2234 | break; |
| 2235 | } |
| 2236 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2237 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2238 | request = (MainThreadRequest) msg.obj; |
| 2239 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | PurchasePremiumCapabilityArgument arg = |
| 2241 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2242 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2243 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2244 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2245 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2246 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2247 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2248 | ar = (AsyncResult) msg.obj; |
| 2249 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2250 | PurchasePremiumCapabilityArgument arg = |
| 2251 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2252 | try { |
| 2253 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2254 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2255 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2256 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2257 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2258 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2259 | } catch (RemoteException e) { |
| 2260 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2261 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2262 | + " failed: " + e; |
| 2263 | if (DBG) log(logStr); |
| 2264 | AnomalyReporter.reportAnomaly( |
| 2265 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2266 | } |
| 2267 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2268 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2269 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2270 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2271 | request = (MainThreadRequest) msg.obj; |
| 2272 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2273 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2274 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2275 | notifyRequester(request); |
| 2276 | break; |
| 2277 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | default: |
| 2279 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2280 | break; |
| 2281 | } |
| 2282 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2283 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2284 | private void notifyRequester(MainThreadRequest request) { |
| 2285 | synchronized (request) { |
| 2286 | request.notifyAll(); |
| 2287 | } |
| 2288 | } |
| 2289 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2290 | private void handleNullReturnEvent(Message msg, String command) { |
| 2291 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2292 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2293 | if (ar.exception == null) { |
| 2294 | request.result = true; |
| 2295 | } else { |
| 2296 | request.result = false; |
| 2297 | if (ar.exception instanceof CommandException) { |
| 2298 | loge(command + ": CommandException: " + ar.exception); |
| 2299 | } else { |
| 2300 | loge(command + ": Unknown exception"); |
| 2301 | } |
| 2302 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2303 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2304 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | /** |
| 2308 | * Posts the specified command to be executed on the main thread, |
| 2309 | * waits for the request to complete, and returns the result. |
| 2310 | * @see #sendRequestAsync |
| 2311 | */ |
| 2312 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2313 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2314 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | /** |
| 2318 | * Posts the specified command to be executed on the main thread, |
| 2319 | * waits for the request to complete, and returns the result. |
| 2320 | * @see #sendRequestAsync |
| 2321 | */ |
| 2322 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2323 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2324 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | /** |
| 2328 | * Posts the specified command to be executed on the main thread, |
| 2329 | * waits for the request to complete, and returns the result. |
| 2330 | * @see #sendRequestAsync |
| 2331 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2332 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2333 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * Posts the specified command to be executed on the main thread, |
| 2338 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2339 | * if not timeout or null otherwise. |
| 2340 | * @see #sendRequestAsync |
| 2341 | */ |
| 2342 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2343 | long timeoutInMs) { |
| 2344 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | /** |
| 2348 | * Posts the specified command to be executed on the main thread, |
| 2349 | * waits for the request to complete, and returns the result. |
| 2350 | * @see #sendRequestAsync |
| 2351 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2352 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2353 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | /** |
| 2357 | * Posts the specified command to be executed on the main thread, |
| 2358 | * waits for the request to complete, and returns the result. |
| 2359 | * @see #sendRequestAsync |
| 2360 | */ |
| 2361 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2362 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2363 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2367 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2368 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2369 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2370 | * @see #sendRequestAsync |
| 2371 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2372 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2373 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2375 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2376 | } |
| 2377 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2378 | MainThreadRequest request = null; |
| 2379 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2380 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2381 | } else if (phone != null) { |
| 2382 | request = new MainThreadRequest(argument, phone, workSource); |
| 2383 | } else { |
| 2384 | request = new MainThreadRequest(argument, subId, workSource); |
| 2385 | } |
| 2386 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2388 | msg.sendToTarget(); |
| 2389 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2390 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2391 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2392 | if (timeoutInMs >= 0) { |
| 2393 | // Wait for at least timeoutInMs before returning null request result |
| 2394 | long now = SystemClock.elapsedRealtime(); |
| 2395 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2396 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2397 | try { |
| 2398 | request.wait(deadline - now); |
| 2399 | } catch (InterruptedException e) { |
| 2400 | // Do nothing, go back and check if request is completed or timeout |
| 2401 | } finally { |
| 2402 | now = SystemClock.elapsedRealtime(); |
| 2403 | } |
| 2404 | } |
| 2405 | } else { |
| 2406 | // Wait for the request to complete |
| 2407 | while (request.result == null) { |
| 2408 | try { |
| 2409 | request.wait(); |
| 2410 | } catch (InterruptedException e) { |
| 2411 | // Do nothing, go back and wait until the request is complete |
| 2412 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 | } |
| 2414 | } |
| 2415 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2416 | if (request.result == null) { |
| 2417 | Log.wtf(LOG_TAG, |
| 2418 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2419 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2420 | return request.result; |
| 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2425 | * Posts the specified command to be executed on the main thread, and |
| 2426 | * returns immediately. |
| 2427 | * @see #sendRequest |
| 2428 | */ |
| 2429 | private void sendRequestAsync(int command) { |
| 2430 | mMainThreadHandler.sendEmptyMessage(command); |
| 2431 | } |
| 2432 | |
| 2433 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2434 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2435 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2436 | */ |
| 2437 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2438 | sendRequestAsync(command, argument, null, null); |
| 2439 | } |
| 2440 | |
| 2441 | /** |
| 2442 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2443 | * @see {@link #sendRequest(int,Object)} |
| 2444 | */ |
| 2445 | private void sendRequestAsync( |
| 2446 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2447 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2448 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2449 | msg.sendToTarget(); |
| 2450 | } |
| 2451 | |
| 2452 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2454 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2455 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2456 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | synchronized (PhoneInterfaceManager.class) { |
| 2458 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2459 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2460 | } else { |
| 2461 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2462 | } |
| 2463 | return sInstance; |
| 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2468 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2470 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2471 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2472 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2473 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2474 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2475 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2477 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2478 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2479 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2480 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2481 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2482 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2483 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2484 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2485 | getDefaultPhone().getContext(), featureFlags); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2486 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2488 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2489 | |
| 2490 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2491 | // entitlementStatus for satellite service. |
| 2492 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2495 | @VisibleForTesting |
| 2496 | public SharedPreferences getSharedPreferences() { |
| 2497 | return mTelephonySharedPreferences; |
| 2498 | } |
| 2499 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2500 | /** |
| 2501 | * Get the default phone for this device. |
| 2502 | */ |
| 2503 | @VisibleForTesting |
| 2504 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2505 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2506 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2507 | } |
| 2508 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2509 | private void publish() { |
| 2510 | if (DBG) log("publish: " + this); |
| 2511 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2512 | TelephonyFrameworkInitializer |
| 2513 | .getTelephonyServiceManager() |
| 2514 | .getTelephonyServiceRegisterer() |
| 2515 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2518 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2519 | if (request.phone != null) { |
| 2520 | return request.phone; |
| 2521 | } else { |
| 2522 | return getPhoneFromSubId(request.subId); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | private Phone getPhoneFromSubId(int subId) { |
| 2527 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2528 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2529 | } |
| 2530 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2531 | /** |
| 2532 | * Get phone object associated with a subscription. |
| 2533 | * Return default phone if phone object associated with subscription is null |
| 2534 | * @param subId - subscriptionId |
| 2535 | * @return phone object associated with a subscription or default phone if null. |
| 2536 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2537 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2538 | Phone phone = getPhoneFromSubId(subId); |
| 2539 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2540 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2541 | phone = getDefaultPhone(); |
| 2542 | } |
| 2543 | return phone; |
| 2544 | } |
| 2545 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2546 | @Nullable |
| 2547 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2548 | Phone phone = getPhoneFromRequest(request); |
| 2549 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2550 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2551 | } |
| 2552 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2553 | /** |
| 2554 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2555 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2556 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2557 | * @return The Phone associated the sub Id |
| 2558 | */ |
| 2559 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2560 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2561 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2562 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2563 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2564 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2565 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2566 | } |
| 2567 | |
| 2568 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2569 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2570 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2573 | private boolean isImsAvailableOnDevice() { |
| 2574 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2575 | if (pm == null) { |
| 2576 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2577 | // so do not throw error and allow. |
| 2578 | return true; |
| 2579 | } |
| 2580 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2581 | } |
| 2582 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2584 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2585 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2586 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2587 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2590 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2591 | if (DBG) log("dial: " + number); |
| 2592 | // No permission check needed here: This is just a wrapper around the |
| 2593 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2594 | // the UI before it does anything. |
| 2595 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2596 | final long identity = Binder.clearCallingIdentity(); |
| 2597 | try { |
| 2598 | String url = createTelUrl(number); |
| 2599 | if (url == null) { |
| 2600 | return; |
| 2601 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2602 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2603 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2604 | PhoneConstants.State state = mCM.getState(subId); |
| 2605 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2606 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2607 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2608 | mApp.startActivity(intent); |
| 2609 | } |
| 2610 | } finally { |
| 2611 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2616 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2619 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | if (DBG) log("call: " + number); |
| 2621 | |
| 2622 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2623 | // need to do a permission check since we're calling startActivity() |
| 2624 | // from the context of the phone app. |
| 2625 | enforceCallPermission(); |
| 2626 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2627 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | != AppOpsManager.MODE_ALLOWED) { |
| 2629 | return; |
| 2630 | } |
| 2631 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2632 | enforceTelephonyFeatureWithException(callingPackage, |
| 2633 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2634 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | String url = createTelUrl(number); |
| 2638 | if (url == null) { |
| 2639 | return; |
| 2640 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2641 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | boolean isValid = false; |
| 2643 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2644 | if (slist != null) { |
| 2645 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2646 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2647 | isValid = true; |
| 2648 | break; |
| 2649 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2650 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2651 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2652 | if (!isValid) { |
| 2653 | return; |
| 2654 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2655 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2657 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2658 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2659 | mApp.startActivity(intent); |
| 2660 | } finally { |
| 2661 | Binder.restoreCallingIdentity(identity); |
| 2662 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2663 | } |
| 2664 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2665 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2666 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2667 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2668 | } |
| 2669 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2670 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2671 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2672 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2673 | } |
| 2674 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2675 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2678 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2679 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2680 | "supplyPinReportResultForSubscriber"); |
| 2681 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2684 | Phone phone = getPhone(subId); |
| 2685 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | checkSimPin.start(); |
| 2687 | return checkSimPin.unlockSim(null, pin); |
| 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
| 2690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2693 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2696 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2697 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2698 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | final long identity = Binder.clearCallingIdentity(); |
| 2700 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2701 | Phone phone = getPhone(subId); |
| 2702 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | checkSimPuk.start(); |
| 2704 | return checkSimPuk.unlockSim(puk, pin); |
| 2705 | } finally { |
| 2706 | Binder.restoreCallingIdentity(identity); |
| 2707 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2711 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2712 | * a synchronous one. |
| 2713 | */ |
| 2714 | private static class UnlockSim extends Thread { |
| 2715 | |
| 2716 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2717 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | |
| 2719 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2720 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2721 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2722 | |
| 2723 | // For replies from SimCard interface |
| 2724 | private Handler mHandler; |
| 2725 | |
| 2726 | // For async handler to identify request type |
| 2727 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2728 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2729 | UnlockSim(int phoneId, IccCard simCard) { |
| 2730 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | mSimCard = simCard; |
| 2732 | } |
| 2733 | |
| 2734 | @Override |
| 2735 | public void run() { |
| 2736 | Looper.prepare(); |
| 2737 | synchronized (UnlockSim.this) { |
| 2738 | mHandler = new Handler() { |
| 2739 | @Override |
| 2740 | public void handleMessage(Message msg) { |
| 2741 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2742 | switch (msg.what) { |
| 2743 | case SUPPLY_PIN_COMPLETE: |
| 2744 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2745 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2746 | mRetryCount = msg.arg1; |
| 2747 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2748 | CommandException.Error error = null; |
| 2749 | if (ar.exception instanceof CommandException) { |
| 2750 | error = ((CommandException) (ar.exception)) |
| 2751 | .getCommandError(); |
| 2752 | } |
| 2753 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2754 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2755 | } else if (error == CommandException.Error.ABORTED) { |
| 2756 | /* When UiccCardApp dispose, handle message and return |
| 2757 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2758 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2759 | } else { |
| 2760 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2761 | } |
| 2762 | } else { |
| 2763 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2765 | mDone = true; |
| 2766 | UnlockSim.this.notifyAll(); |
| 2767 | } |
| 2768 | break; |
| 2769 | } |
| 2770 | } |
| 2771 | }; |
| 2772 | UnlockSim.this.notifyAll(); |
| 2773 | } |
| 2774 | Looper.loop(); |
| 2775 | } |
| 2776 | |
| 2777 | /* |
| 2778 | * Use PIN or PUK to unlock SIM card |
| 2779 | * |
| 2780 | * If PUK is null, unlock SIM card with PIN |
| 2781 | * |
| 2782 | * 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] | 2783 | * |
| 2784 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2785 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2786 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2787 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2788 | |
| 2789 | while (mHandler == null) { |
| 2790 | try { |
| 2791 | wait(); |
| 2792 | } catch (InterruptedException e) { |
| 2793 | Thread.currentThread().interrupt(); |
| 2794 | } |
| 2795 | } |
| 2796 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2797 | |
| 2798 | if (puk == null) { |
| 2799 | mSimCard.supplyPin(pin, callback); |
| 2800 | } else { |
| 2801 | mSimCard.supplyPuk(puk, pin, callback); |
| 2802 | } |
| 2803 | |
| 2804 | while (!mDone) { |
| 2805 | try { |
| 2806 | Log.d(LOG_TAG, "wait for done"); |
| 2807 | wait(); |
| 2808 | } catch (InterruptedException e) { |
| 2809 | // Restore the interrupted status |
| 2810 | Thread.currentThread().interrupt(); |
| 2811 | } |
| 2812 | } |
| 2813 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2814 | int[] resultArray = new int[2]; |
| 2815 | resultArray[0] = mResult; |
| 2816 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2817 | |
| 2818 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2819 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2820 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2821 | // This instance is no longer reused, so quit its thread's looper. |
| 2822 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2823 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2824 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | } |
| 2826 | } |
| 2827 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2828 | /** |
| 2829 | * This method has been removed due to privacy and stability concerns. |
| 2830 | */ |
| 2831 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2832 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2833 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2834 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2837 | @Override |
| 2838 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2839 | mApp.getSystemService(AppOpsManager.class) |
| 2840 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2841 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2842 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2843 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2844 | // Callers targeting S have no business invoking this method. |
| 2845 | return; |
| 2846 | } |
| 2847 | |
| 2848 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2849 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2850 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2851 | .setCallingPackage(callingPackage) |
| 2852 | .setCallingFeatureId(null) |
| 2853 | .setCallingPid(Binder.getCallingPid()) |
| 2854 | .setCallingUid(Binder.getCallingUid()) |
| 2855 | .setMethod("updateServiceLocation") |
| 2856 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2857 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2858 | .build()); |
| 2859 | // Apps that lack location permission have no business calling this method; |
| 2860 | // however, because no permission was declared in the public API, denials must |
| 2861 | // all be "soft". |
| 2862 | switch (locationResult) { |
| 2863 | case DENIED_HARD: /* fall through */ |
| 2864 | case DENIED_SOFT: |
| 2865 | return; |
| 2866 | } |
| 2867 | |
| 2868 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2869 | final long identity = Binder.clearCallingIdentity(); |
| 2870 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2871 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | } finally { |
| 2873 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2877 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2878 | @Override |
| 2879 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2880 | return isRadioOnWithFeature(callingPackage, null); |
| 2881 | } |
| 2882 | |
| 2883 | |
| 2884 | @Override |
| 2885 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2886 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2887 | callingFeatureId); |
| 2888 | } |
| 2889 | |
| 2890 | @Deprecated |
| 2891 | @Override |
| 2892 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2893 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2896 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2897 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2898 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2899 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2900 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2901 | return false; |
| 2902 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2903 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2904 | enforceTelephonyFeatureWithException(callingPackage, |
| 2905 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2906 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2907 | final long identity = Binder.clearCallingIdentity(); |
| 2908 | try { |
| 2909 | return isRadioOnForSubscriber(subId); |
| 2910 | } finally { |
| 2911 | Binder.restoreCallingIdentity(identity); |
| 2912 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2916 | final long identity = Binder.clearCallingIdentity(); |
| 2917 | try { |
| 2918 | final Phone phone = getPhone(subId); |
| 2919 | if (phone != null) { |
| 2920 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2921 | } else { |
| 2922 | return false; |
| 2923 | } |
| 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2926 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2930 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2931 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2932 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2933 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2934 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2936 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2937 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2938 | |
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 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2944 | } |
| 2945 | } finally { |
| 2946 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2947 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2951 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2954 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2955 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | |
| 2957 | final long identity = Binder.clearCallingIdentity(); |
| 2958 | try { |
| 2959 | final Phone phone = getPhone(subId); |
| 2960 | if (phone == null) { |
| 2961 | return false; |
| 2962 | } |
| 2963 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2964 | toggleRadioOnOffForSubscriber(subId); |
| 2965 | } |
| 2966 | return true; |
| 2967 | } finally { |
| 2968 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2969 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2970 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2971 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2972 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2973 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2974 | |
| 2975 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2976 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2977 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2978 | /* |
| 2979 | * If any of the Radios are available, it will need to be |
| 2980 | * shutdown. So return true if any Radio is available. |
| 2981 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2982 | final long identity = Binder.clearCallingIdentity(); |
| 2983 | try { |
| 2984 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2985 | Phone phone = PhoneFactory.getPhone(i); |
| 2986 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2987 | } |
| 2988 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2989 | return false; |
| 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2992 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2995 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2996 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2997 | enforceModifyPermission(); |
| 2998 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2999 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3000 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3005 | logv("Shutting down Phone " + i); |
| 3006 | shutdownRadioUsingPhoneId(i); |
| 3007 | } |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3014 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3015 | if (phone != null && phone.isRadioAvailable()) { |
| 3016 | phone.shutdownRadio(); |
| 3017 | } |
| 3018 | } |
| 3019 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3020 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3021 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3023 | if (!turnOn) { |
| 3024 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3025 | } |
| 3026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
| 3029 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3030 | if (defaultPhone != null) { |
| 3031 | defaultPhone.setRadioPower(turnOn); |
| 3032 | return true; |
| 3033 | } else { |
| 3034 | loge("There's no default phone."); |
| 3035 | return false; |
| 3036 | } |
| 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3039 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3042 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3043 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3045 | if (!turnOn) { |
| 3046 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3047 | + ",callingPackage=" + getCurrentPackageName()); |
| 3048 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | final Phone phone = getPhone(subId); |
| 3052 | if (phone != null) { |
| 3053 | phone.setRadioPower(turnOn); |
| 3054 | return true; |
| 3055 | } else { |
| 3056 | return false; |
| 3057 | } |
| 3058 | } finally { |
| 3059 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3060 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3063 | /** |
| 3064 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3065 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3066 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3067 | * powering it off, and these radio off votes will be cleared. |
| 3068 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3069 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3070 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3071 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3072 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3073 | * check its vote. |
| 3074 | * |
| 3075 | * @param subId The subscription ID. |
| 3076 | * @param reason The reason for powering off radio. |
| 3077 | * @return true on success and false on failure. |
| 3078 | */ |
| 3079 | public boolean requestRadioPowerOffForReason(int subId, |
| 3080 | @TelephonyManager.RadioPowerReason int reason) { |
| 3081 | enforceModifyPermission(); |
| 3082 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3083 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3084 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3085 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3086 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3087 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3088 | final long identity = Binder.clearCallingIdentity(); |
| 3089 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3090 | boolean result = false; |
| 3091 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3092 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3093 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3094 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3095 | if (!result) { |
| 3096 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3097 | } |
| 3098 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3099 | } finally { |
| 3100 | Binder.restoreCallingIdentity(identity); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | /** |
| 3105 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3106 | * {@link requestRadioPowerOffForReason}. |
| 3107 | * |
| 3108 | * @param subId The subscription ID. |
| 3109 | * @param reason The reason for powering off radio. |
| 3110 | * @return true on success and false on failure. |
| 3111 | */ |
| 3112 | public boolean clearRadioPowerOffForReason(int subId, |
| 3113 | @TelephonyManager.RadioPowerReason int reason) { |
| 3114 | enforceModifyPermission(); |
| 3115 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3116 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3117 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3118 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3119 | final long identity = Binder.clearCallingIdentity(); |
| 3120 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3121 | boolean result = false; |
| 3122 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3123 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3124 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3125 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3126 | if (!result) { |
| 3127 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3128 | } |
| 3129 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3130 | } finally { |
| 3131 | Binder.restoreCallingIdentity(identity); |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3137 | * |
| 3138 | * @param subId The subscription ID. |
| 3139 | * @param callingPackage The package making the call. |
| 3140 | * @param callingFeatureId The feature in the package. |
| 3141 | * @return List of reasons for powering off radio. |
| 3142 | */ |
| 3143 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3144 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3145 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3146 | enforceTelephonyFeatureWithException(callingPackage, |
| 3147 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3148 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | List result = new ArrayList(); |
| 3151 | try { |
| 3152 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3153 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3154 | return result; |
| 3155 | } |
| 3156 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3157 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3158 | if (phone != null) { |
| 3159 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3160 | } else { |
| 3161 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3162 | } |
| 3163 | } finally { |
| 3164 | Binder.restoreCallingIdentity(identity); |
| 3165 | } |
| 3166 | return result; |
| 3167 | } |
| 3168 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3169 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3170 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3171 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3172 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3173 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3174 | enforceTelephonyFeatureWithException(callingPackage, |
| 3175 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3176 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3177 | final long identity = Binder.clearCallingIdentity(); |
| 3178 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3179 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3180 | final Phone phone = getPhone(subId); |
| 3181 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3182 | phone.getDataSettingsManager().setDataEnabled( |
| 3183 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 | return true; |
| 3185 | } else { |
| 3186 | return false; |
| 3187 | } |
| 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3190 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3193 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3194 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3195 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3196 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3197 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3198 | enforceTelephonyFeatureWithException(callingPackage, |
| 3199 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3200 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | final long identity = Binder.clearCallingIdentity(); |
| 3202 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3203 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3204 | final Phone phone = getPhone(subId); |
| 3205 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3206 | phone.getDataSettingsManager().setDataEnabled( |
| 3207 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | return true; |
| 3209 | } else { |
| 3210 | return false; |
| 3211 | } |
| 3212 | } finally { |
| 3213 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3214 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3217 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3218 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3219 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3220 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | final Phone phone = getPhone(subId); |
| 3225 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3226 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | } else { |
| 3228 | return false; |
| 3229 | } |
| 3230 | } finally { |
| 3231 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3232 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3236 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3239 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3240 | enforceCallPermission(); |
| 3241 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3242 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3243 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | final long identity = Binder.clearCallingIdentity(); |
| 3246 | try { |
| 3247 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3248 | return; |
| 3249 | } |
| 3250 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3251 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3252 | } finally { |
| 3253 | Binder.restoreCallingIdentity(identity); |
| 3254 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3255 | }; |
| 3256 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3257 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3258 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3259 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3260 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3261 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3263 | final long identity = Binder.clearCallingIdentity(); |
| 3264 | try { |
| 3265 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3266 | return false; |
| 3267 | } |
| 3268 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3269 | } finally { |
| 3270 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3271 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3274 | /** |
| 3275 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3276 | * tag on getCallState Binder call. |
| 3277 | */ |
| 3278 | @Deprecated |
| 3279 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3281 | if (CompatChanges.isChangeEnabled( |
| 3282 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3283 | Binder.getCallingUid())) { |
| 3284 | // Do not allow this API to be called on API version 31+, it should only be |
| 3285 | // called on old apps using this Binder call directly. |
| 3286 | throw new SecurityException("This method can only be used for applications " |
| 3287 | + "targeting API version 30 or less."); |
| 3288 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3289 | final long identity = Binder.clearCallingIdentity(); |
| 3290 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3291 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3292 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3293 | } finally { |
| 3294 | Binder.restoreCallingIdentity(identity); |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | @Override |
| 3299 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3300 | if (CompatChanges.isChangeEnabled( |
| 3301 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3302 | Binder.getCallingUid())) { |
| 3303 | // Check READ_PHONE_STATE for API version 31+ |
| 3304 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3305 | featureId, "getCallStateForSubscription")) { |
| 3306 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3307 | + "targeting API level 31+."); |
| 3308 | } |
| 3309 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3310 | |
| 3311 | enforceTelephonyFeatureWithException(callingPackage, |
| 3312 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3313 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3314 | final long identity = Binder.clearCallingIdentity(); |
| 3315 | try { |
| 3316 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3317 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3318 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3319 | } finally { |
| 3320 | Binder.restoreCallingIdentity(identity); |
| 3321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3322 | } |
| 3323 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3324 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3325 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3326 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | @Override |
| 3330 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3331 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3332 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3336 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3337 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3338 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3339 | } else { |
| 3340 | return PhoneConstantConversions.convertDataState( |
| 3341 | PhoneConstants.DataState.DISCONNECTED); |
| 3342 | } |
| 3343 | } finally { |
| 3344 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3345 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3348 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3349 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3350 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3354 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3355 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3356 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | final long identity = Binder.clearCallingIdentity(); |
| 3359 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3360 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3362 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3363 | } else { |
| 3364 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 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 | |
| 3371 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3372 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3373 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3374 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3375 | |
| 3376 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3377 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3378 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3379 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3380 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3381 | .setCallingPid(Binder.getCallingPid()) |
| 3382 | .setCallingUid(Binder.getCallingUid()) |
| 3383 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3384 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3385 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3386 | .build()); |
| 3387 | switch (locationResult) { |
| 3388 | case DENIED_HARD: |
| 3389 | throw new SecurityException("Not allowed to access cell location"); |
| 3390 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3391 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3392 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3395 | enforceTelephonyFeatureWithException(callingPackage, |
| 3396 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3397 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3398 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3399 | final long identity = Binder.clearCallingIdentity(); |
| 3400 | try { |
| 3401 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3402 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3403 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3404 | } finally { |
| 3405 | Binder.restoreCallingIdentity(identity); |
| 3406 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3409 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3410 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3411 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3412 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3413 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3414 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3415 | // registered cell info, so return a NULL country instead. |
| 3416 | final long identity = Binder.clearCallingIdentity(); |
| 3417 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3418 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3419 | // Get default phone in this case. |
| 3420 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3421 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3422 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3423 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3424 | if (phone == null) return ""; |
| 3425 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3426 | if (sst == null) return ""; |
| 3427 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3428 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3429 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3430 | } finally { |
| 3431 | Binder.restoreCallingIdentity(identity); |
| 3432 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3435 | /** |
| 3436 | * This method was removed due to potential issues caused by performing partial |
| 3437 | * updates of service state, and lack of a credible use case. |
| 3438 | * |
| 3439 | * This has the ability to break the telephony implementation by disabling notification of |
| 3440 | * changes in device connectivity. DO NOT USE THIS! |
| 3441 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3442 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3443 | public void enableLocationUpdates() { |
| 3444 | mApp.enforceCallingOrSelfPermission( |
| 3445 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3448 | /** |
| 3449 | * This method was removed due to potential issues caused by performing partial |
| 3450 | * updates of service state, and lack of a credible use case. |
| 3451 | * |
| 3452 | * This has the ability to break the telephony implementation by disabling notification of |
| 3453 | * changes in device connectivity. DO NOT USE THIS! |
| 3454 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3455 | @Override |
| 3456 | public void disableLocationUpdates() { |
| 3457 | mApp.enforceCallingOrSelfPermission( |
| 3458 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | @Override |
| 3462 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3463 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3464 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3465 | try { |
| 3466 | mApp.getSystemService(AppOpsManager.class) |
| 3467 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3468 | } catch (SecurityException e) { |
| 3469 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3470 | throw e; |
| 3471 | } |
| 3472 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3473 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3474 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3475 | throw new SecurityException( |
| 3476 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3477 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3478 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3479 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3480 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3481 | return null; |
| 3482 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3483 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3484 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3485 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3486 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3487 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3488 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3489 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3490 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3491 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3492 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3493 | for (CellInfo ci : info) { |
| 3494 | if (ci instanceof CellInfoGsm) { |
| 3495 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3496 | } else if (ci instanceof CellInfoWcdma) { |
| 3497 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3498 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3499 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3500 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3503 | private List<CellInfo> getCachedCellInfo() { |
| 3504 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3505 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3506 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3507 | if (info != null) cellInfos.addAll(info); |
| 3508 | } |
| 3509 | return cellInfos; |
| 3510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3511 | |
| 3512 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3513 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3514 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3515 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3516 | |
| 3517 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3518 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3519 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3520 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3521 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3522 | .setCallingPid(Binder.getCallingPid()) |
| 3523 | .setCallingUid(Binder.getCallingUid()) |
| 3524 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3525 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3526 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3527 | .build()); |
| 3528 | switch (locationResult) { |
| 3529 | case DENIED_HARD: |
| 3530 | throw new SecurityException("Not allowed to access cell info"); |
| 3531 | case DENIED_SOFT: |
| 3532 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3535 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3536 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3537 | return getCachedCellInfo(); |
| 3538 | } |
| 3539 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3540 | enforceTelephonyFeatureWithException(callingPackage, |
| 3541 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3542 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3543 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3544 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | final long identity = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3548 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3549 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3550 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3551 | if (info != null) cellInfos.addAll(info); |
| 3552 | } |
| 3553 | return cellInfos; |
| 3554 | } finally { |
| 3555 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3556 | } |
| 3557 | } |
| 3558 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3559 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3560 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3561 | String callingFeatureId) { |
| 3562 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3563 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3567 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3568 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3569 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3570 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3573 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3574 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3575 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3576 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3577 | |
| 3578 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3579 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3580 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3581 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3582 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3583 | .setCallingPid(Binder.getCallingPid()) |
| 3584 | .setCallingUid(Binder.getCallingUid()) |
| 3585 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3586 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3587 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3588 | .build()); |
| 3589 | switch (locationResult) { |
| 3590 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3591 | if (TelephonyPermissions |
| 3592 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3593 | // Safetynet logging for b/154934934 |
| 3594 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3595 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3596 | throw new SecurityException("Not allowed to access cell info"); |
| 3597 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3598 | if (TelephonyPermissions |
| 3599 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3600 | // Safetynet logging for b/154934934 |
| 3601 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3602 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3603 | try { |
| 3604 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3605 | } catch (RemoteException re) { |
| 3606 | // Drop without consequences |
| 3607 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3608 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3609 | } |
| 3610 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3611 | enforceTelephonyFeatureWithException(callingPackage, |
| 3612 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3613 | |
| 3614 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3615 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3616 | |
| 3617 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3618 | } |
| 3619 | |
| 3620 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3621 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3622 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3623 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3624 | |
| 3625 | final long identity = Binder.clearCallingIdentity(); |
| 3626 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3627 | Phone phone = getPhone(subId); |
| 3628 | if (phone == null) { |
| 3629 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3630 | } else { |
| 3631 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3632 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3633 | } finally { |
| 3634 | Binder.restoreCallingIdentity(identity); |
| 3635 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3638 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3639 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3640 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3641 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3642 | return null; |
| 3643 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3644 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3645 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3646 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3647 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3648 | return null; |
| 3649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3650 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3651 | enforceTelephonyFeatureWithException(callingPackage, |
| 3652 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3653 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | final long identity = Binder.clearCallingIdentity(); |
| 3655 | try { |
| 3656 | return phone.getImei(); |
| 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
| 3659 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3663 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3664 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3665 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3666 | callingFeatureId, "getPrimaryImei")) { |
| 3667 | throw new SecurityException("Caller does not have permission"); |
| 3668 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3669 | |
| 3670 | enforceTelephonyFeatureWithException(callingPackage, |
| 3671 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3672 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3673 | final long identity = Binder.clearCallingIdentity(); |
| 3674 | try { |
| 3675 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3676 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3677 | return phone.getImei(); |
| 3678 | } |
| 3679 | } |
| 3680 | throw new UnsupportedOperationException("Operation not supported"); |
| 3681 | } finally { |
| 3682 | Binder.restoreCallingIdentity(identity); |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3687 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3688 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3689 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3690 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3691 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3692 | String tac = null; |
| 3693 | if (phone != null) { |
| 3694 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3695 | try { |
| 3696 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3697 | } catch (IndexOutOfBoundsException e) { |
| 3698 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3699 | return null; |
| 3700 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3701 | } |
| 3702 | return tac; |
| 3703 | } |
| 3704 | |
| 3705 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3706 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3707 | try { |
| 3708 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3709 | } catch (SecurityException se) { |
| 3710 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3711 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3712 | + Binder.getCallingUid()); |
| 3713 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3714 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3715 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3716 | return null; |
| 3717 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3718 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3719 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3720 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3721 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3722 | return null; |
| 3723 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3724 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3725 | enforceTelephonyFeatureWithException(callingPackage, |
| 3726 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3727 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3728 | final long identity = Binder.clearCallingIdentity(); |
| 3729 | try { |
| 3730 | return phone.getMeid(); |
| 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
| 3733 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3737 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3738 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3739 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3740 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3741 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3742 | String manufacturerCode = null; |
| 3743 | if (phone != null) { |
| 3744 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3745 | try { |
| 3746 | manufacturerCode = |
| 3747 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3748 | } catch (IndexOutOfBoundsException e) { |
| 3749 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3750 | return null; |
| 3751 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3752 | } |
| 3753 | return manufacturerCode; |
| 3754 | } |
| 3755 | |
| 3756 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3757 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3758 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3759 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3760 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3761 | return null; |
| 3762 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3763 | int subId = phone.getSubId(); |
| 3764 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3765 | mApp, subId, callingPackage, callingFeatureId, |
| 3766 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3767 | return null; |
| 3768 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3769 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3770 | enforceTelephonyFeatureWithException(callingPackage, |
| 3771 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3772 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3773 | final long identity = Binder.clearCallingIdentity(); |
| 3774 | try { |
| 3775 | return phone.getDeviceSvn(); |
| 3776 | } finally { |
| 3777 | Binder.restoreCallingIdentity(identity); |
| 3778 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3781 | @Override |
| 3782 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3783 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3784 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3786 | final long identity = Binder.clearCallingIdentity(); |
| 3787 | try { |
| 3788 | final Phone phone = getPhone(subId); |
| 3789 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3790 | } finally { |
| 3791 | Binder.restoreCallingIdentity(identity); |
| 3792 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | @Override |
| 3796 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3797 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3798 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3799 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | final long identity = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | final Phone phone = getPhone(subId); |
| 3803 | return phone == null ? null : phone.getCarrierName(); |
| 3804 | } finally { |
| 3805 | Binder.restoreCallingIdentity(identity); |
| 3806 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3807 | } |
| 3808 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3809 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3810 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3811 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3812 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3813 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3814 | final long identity = Binder.clearCallingIdentity(); |
| 3815 | try { |
| 3816 | final Phone phone = getPhone(subId); |
| 3817 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3818 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3819 | } finally { |
| 3820 | Binder.restoreCallingIdentity(identity); |
| 3821 | } |
| 3822 | } |
| 3823 | |
| 3824 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3825 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3826 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3827 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3828 | "getSubscriptionSpecificCarrierName"); |
| 3829 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
| 3832 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3833 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3834 | } finally { |
| 3835 | Binder.restoreCallingIdentity(identity); |
| 3836 | } |
| 3837 | } |
| 3838 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3839 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3840 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3841 | if (!isSubscriptionMccMnc) { |
| 3842 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3843 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3844 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3845 | if (phone == null) { |
| 3846 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3847 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3848 | |
| 3849 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3850 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3851 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3852 | final long identity = Binder.clearCallingIdentity(); |
| 3853 | try { |
| 3854 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3855 | } finally { |
| 3856 | Binder.restoreCallingIdentity(identity); |
| 3857 | } |
| 3858 | } |
| 3859 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3860 | // |
| 3861 | // Internal helper methods. |
| 3862 | // |
| 3863 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3864 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3865 | * Make sure the caller is the calling package itself |
| 3866 | * |
| 3867 | * @throws SecurityException if the caller is not the calling package |
| 3868 | */ |
| 3869 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3870 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3871 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3872 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3873 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3874 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3875 | } catch (PackageManager.NameNotFoundException e) { |
| 3876 | // packageUid is -1 |
| 3877 | } |
| 3878 | if (packageUid != callingUid) { |
| 3879 | throw new SecurityException(message + ": Package " + callingPackage |
| 3880 | + " does not belong to " + callingUid); |
| 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3885 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3886 | * |
| 3887 | * @throws SecurityException if the caller does not have the required permission |
| 3888 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3889 | @VisibleForTesting |
| 3890 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3891 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3892 | } |
| 3893 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3894 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3895 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3896 | * |
| 3897 | * @throws SecurityException if the caller does not have the required permission |
| 3898 | */ |
| 3899 | @VisibleForTesting |
| 3900 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3901 | enforceReadPermission(null); |
| 3902 | } |
| 3903 | |
| 3904 | /** |
| 3905 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3906 | * |
| 3907 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3908 | */ |
| 3909 | @VisibleForTesting |
| 3910 | public void enforceReadPermission(String msg) { |
| 3911 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3912 | } |
| 3913 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3914 | private void enforceActiveEmergencySessionPermission() { |
| 3915 | mApp.enforceCallingOrSelfPermission( |
| 3916 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3917 | } |
| 3918 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3919 | /** |
| 3920 | * Make sure the caller has the CALL_PHONE permission. |
| 3921 | * |
| 3922 | * @throws SecurityException if the caller does not have the required permission |
| 3923 | */ |
| 3924 | private void enforceCallPermission() { |
| 3925 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3926 | } |
| 3927 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3928 | private void enforceSettingsPermission() { |
| 3929 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3932 | private void enforceRebootPermission() { |
| 3933 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3934 | } |
| 3935 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3936 | /** |
| 3937 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3938 | * @param message - log message to print. |
| 3939 | * @throws SecurityException if the caller does not have the required permission |
| 3940 | */ |
| 3941 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3942 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3943 | } |
| 3944 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3945 | private String createTelUrl(String number) { |
| 3946 | if (TextUtils.isEmpty(number)) { |
| 3947 | return null; |
| 3948 | } |
| 3949 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3950 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3953 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3954 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3955 | } |
| 3956 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3957 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3958 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3959 | } |
| 3960 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3961 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3962 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3965 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3966 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3967 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3970 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3971 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3972 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3973 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 3974 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3975 | final long identity = Binder.clearCallingIdentity(); |
| 3976 | try { |
| 3977 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3978 | if (phone == null) { |
| 3979 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3980 | } else { |
| 3981 | return phone.getPhoneType(); |
| 3982 | } |
| 3983 | } finally { |
| 3984 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3985 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | /** |
| 3989 | * Returns the CDMA ERI icon index to display |
| 3990 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3991 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3992 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3993 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3994 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3997 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3998 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3999 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4000 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4001 | mApp, subId, callingPackage, callingFeatureId, |
| 4002 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4003 | return -1; |
| 4004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4005 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4006 | enforceTelephonyFeatureWithException(callingPackage, |
| 4007 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4008 | "getCdmaEriIconIndexForSubscriber"); |
| 4009 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4010 | final long identity = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | final Phone phone = getPhone(subId); |
| 4013 | if (phone != null) { |
| 4014 | return phone.getCdmaEriIconIndex(); |
| 4015 | } else { |
| 4016 | return -1; |
| 4017 | } |
| 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4020 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * Returns the CDMA ERI icon mode, |
| 4025 | * 0 - ON |
| 4026 | * 1 - FLASHING |
| 4027 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4028 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4029 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4030 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4031 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4034 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4035 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4036 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4037 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4038 | mApp, subId, callingPackage, callingFeatureId, |
| 4039 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4040 | return -1; |
| 4041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | |
| 4043 | final long identity = Binder.clearCallingIdentity(); |
| 4044 | try { |
| 4045 | final Phone phone = getPhone(subId); |
| 4046 | if (phone != null) { |
| 4047 | return phone.getCdmaEriIconMode(); |
| 4048 | } else { |
| 4049 | return -1; |
| 4050 | } |
| 4051 | } finally { |
| 4052 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4053 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | /** |
| 4057 | * Returns the CDMA ERI text, |
| 4058 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4059 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4060 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4061 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4062 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4063 | } |
| 4064 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4065 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4066 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4067 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4069 | mApp, subId, callingPackage, callingFeatureId, |
| 4070 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4071 | return null; |
| 4072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4073 | |
| 4074 | final long identity = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | final Phone phone = getPhone(subId); |
| 4077 | if (phone != null) { |
| 4078 | return phone.getCdmaEriText(); |
| 4079 | } else { |
| 4080 | return null; |
| 4081 | } |
| 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4084 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4088 | * Returns the CDMA MDN. |
| 4089 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4090 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4091 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4093 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4094 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4095 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4096 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4098 | final long identity = Binder.clearCallingIdentity(); |
| 4099 | try { |
| 4100 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4101 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4102 | return phone.getLine1Number(); |
| 4103 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4104 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | return null; |
| 4106 | } |
| 4107 | } finally { |
| 4108 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4109 | } |
| 4110 | } |
| 4111 | |
| 4112 | /** |
| 4113 | * Returns the CDMA MIN. |
| 4114 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4115 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4116 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4117 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4118 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4119 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4120 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4121 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4122 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4123 | final long identity = Binder.clearCallingIdentity(); |
| 4124 | try { |
| 4125 | final Phone phone = getPhone(subId); |
| 4126 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4127 | return phone.getCdmaMin(); |
| 4128 | } else { |
| 4129 | return null; |
| 4130 | } |
| 4131 | } finally { |
| 4132 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4136 | @Override |
| 4137 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4138 | INumberVerificationCallback callback, String callingPackage) { |
| 4139 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4140 | != PERMISSION_GRANTED) { |
| 4141 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4142 | } |
| 4143 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4144 | |
| 4145 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4146 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4147 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4148 | + "calling package: " + callingPackage |
| 4149 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4150 | } |
| 4151 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4152 | enforceTelephonyFeatureWithException(callingPackage, |
| 4153 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4154 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4155 | if (range == null) { |
| 4156 | throw new NullPointerException("Range must be non-null"); |
| 4157 | } |
| 4158 | |
| 4159 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4160 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4161 | |
| 4162 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4163 | } |
| 4164 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4165 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4166 | * Returns true if CDMA provisioning needs to run. |
| 4167 | */ |
| 4168 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4169 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4170 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4171 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | final long identity = Binder.clearCallingIdentity(); |
| 4173 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4174 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4175 | } finally { |
| 4176 | Binder.restoreCallingIdentity(identity); |
| 4177 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4181 | * Sets the voice mail number of a given subId. |
| 4182 | */ |
| 4183 | @Override |
| 4184 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4185 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4186 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4187 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4188 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4189 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4190 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4191 | final long identity = Binder.clearCallingIdentity(); |
| 4192 | try { |
| 4193 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4194 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4195 | return success; |
| 4196 | } finally { |
| 4197 | Binder.restoreCallingIdentity(identity); |
| 4198 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4199 | } |
| 4200 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4201 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4202 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4203 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4204 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4205 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4206 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4207 | throw new SecurityException("caller must be system dialer"); |
| 4208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4209 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4210 | enforceTelephonyFeatureWithException(callingPackage, |
| 4211 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4212 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
| 4215 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4216 | if (phoneAccountHandle == null) { |
| 4217 | return null; |
| 4218 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4219 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 | } finally { |
| 4221 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4222 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4226 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4227 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4228 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4229 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4230 | mApp, subId, callingPackage, callingFeatureId, |
| 4231 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4232 | return null; |
| 4233 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4234 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4235 | enforceTelephonyFeatureWithException(callingPackage, |
| 4236 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4237 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4238 | final long identity = Binder.clearCallingIdentity(); |
| 4239 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4240 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4241 | } finally { |
| 4242 | Binder.restoreCallingIdentity(identity); |
| 4243 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4247 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4248 | VisualVoicemailSmsFilterSettings settings) { |
| 4249 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4251 | enforceTelephonyFeatureWithException(callingPackage, |
| 4252 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
| 4253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | final long identity = Binder.clearCallingIdentity(); |
| 4255 | try { |
| 4256 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4257 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4258 | } finally { |
| 4259 | Binder.restoreCallingIdentity(identity); |
| 4260 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4264 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4265 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
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, "disableVisualVoicemailSmsFilter"); |
| 4269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4270 | final long identity = Binder.clearCallingIdentity(); |
| 4271 | try { |
| 4272 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4273 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4274 | } finally { |
| 4275 | Binder.restoreCallingIdentity(identity); |
| 4276 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4277 | } |
| 4278 | |
| 4279 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4280 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4281 | String callingPackage, int subId) { |
| 4282 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4287 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | } finally { |
| 4289 | Binder.restoreCallingIdentity(identity); |
| 4290 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4294 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4295 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4296 | |
| 4297 | final long identity = Binder.clearCallingIdentity(); |
| 4298 | try { |
| 4299 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4300 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4301 | } finally { |
| 4302 | Binder.restoreCallingIdentity(identity); |
| 4303 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4307 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4308 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4309 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4310 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4311 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4312 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4313 | |
| 4314 | enforceTelephonyFeatureWithException(callingPackage, |
| 4315 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4316 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4317 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4318 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4319 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4320 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4321 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4322 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4323 | * Sets the voice activation state of a given subId. |
| 4324 | */ |
| 4325 | @Override |
| 4326 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4327 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4328 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4329 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4330 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4331 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4332 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4333 | final long identity = Binder.clearCallingIdentity(); |
| 4334 | try { |
| 4335 | final Phone phone = getPhone(subId); |
| 4336 | if (phone != null) { |
| 4337 | phone.setVoiceActivationState(activationState); |
| 4338 | } else { |
| 4339 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4340 | } |
| 4341 | } finally { |
| 4342 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | /** |
| 4347 | * Sets the data activation state of a given subId. |
| 4348 | */ |
| 4349 | @Override |
| 4350 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4352 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4353 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4354 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4355 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4356 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4357 | final long identity = Binder.clearCallingIdentity(); |
| 4358 | try { |
| 4359 | final Phone phone = getPhone(subId); |
| 4360 | if (phone != null) { |
| 4361 | phone.setDataActivationState(activationState); |
| 4362 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4363 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4364 | } |
| 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | /** |
| 4371 | * Returns the voice activation state of a given subId. |
| 4372 | */ |
| 4373 | @Override |
| 4374 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4375 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4377 | enforceTelephonyFeatureWithException(callingPackage, |
| 4378 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4379 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4380 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | final long identity = Binder.clearCallingIdentity(); |
| 4382 | try { |
| 4383 | if (phone != null) { |
| 4384 | return phone.getVoiceActivationState(); |
| 4385 | } else { |
| 4386 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4387 | } |
| 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | /** |
| 4394 | * Returns the data activation state of a given subId. |
| 4395 | */ |
| 4396 | @Override |
| 4397 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4398 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4399 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4400 | enforceTelephonyFeatureWithException(callingPackage, |
| 4401 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4402 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4403 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | final long identity = Binder.clearCallingIdentity(); |
| 4405 | try { |
| 4406 | if (phone != null) { |
| 4407 | return phone.getDataActivationState(); |
| 4408 | } else { |
| 4409 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4410 | } |
| 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4417 | * Returns the unread count of voicemails for a subId |
| 4418 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4419 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4420 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4421 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4422 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4423 | mApp, subId, callingPackage, callingFeatureId, |
| 4424 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4425 | return 0; |
| 4426 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | final long identity = Binder.clearCallingIdentity(); |
| 4428 | try { |
| 4429 | final Phone phone = getPhone(subId); |
| 4430 | if (phone != null) { |
| 4431 | return phone.getVoiceMessageCount(); |
| 4432 | } else { |
| 4433 | return 0; |
| 4434 | } |
| 4435 | } finally { |
| 4436 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4441 | * returns true, if the device is in a state where both voice and data |
| 4442 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4443 | */ |
| 4444 | @Override |
| 4445 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4446 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4447 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4448 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4449 | final long identity = Binder.clearCallingIdentity(); |
| 4450 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4451 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4452 | } finally { |
| 4453 | Binder.restoreCallingIdentity(identity); |
| 4454 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4458 | * Send the dialer code if called from the current default dialer or the caller has |
| 4459 | * carrier privilege. |
| 4460 | * @param inputCode The dialer code to send |
| 4461 | */ |
| 4462 | @Override |
| 4463 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4464 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4465 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4466 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4467 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4468 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4469 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4470 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4471 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4473 | enforceTelephonyFeatureWithException(callingPackage, |
| 4474 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4475 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | final long identity = Binder.clearCallingIdentity(); |
| 4477 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4478 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4479 | } finally { |
| 4480 | Binder.restoreCallingIdentity(identity); |
| 4481 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4482 | } |
| 4483 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4484 | @Override |
| 4485 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4486 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4487 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4488 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4489 | |
| 4490 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4491 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4492 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4493 | final long identity = Binder.clearCallingIdentity(); |
| 4494 | try { |
| 4495 | if (!isActiveSubscription(subId)) { |
| 4496 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4497 | } |
| 4498 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4499 | } finally { |
| 4500 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4501 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4504 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4505 | public boolean isInEmergencySmsMode() { |
| 4506 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4507 | |
| 4508 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4509 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4510 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4511 | final long identity = Binder.clearCallingIdentity(); |
| 4512 | try { |
| 4513 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4514 | if (phone.isInEmergencySmsMode()) { |
| 4515 | return true; |
| 4516 | } |
| 4517 | } |
| 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
| 4520 | } |
| 4521 | return false; |
| 4522 | } |
| 4523 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4524 | /** |
| 4525 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4526 | * @param subId The subscription to use to check the configuration. |
| 4527 | * @param c The callback that will be used to send the result. |
| 4528 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4529 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4530 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4531 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4532 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4533 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4534 | |
| 4535 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4536 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4537 | "IMS not available on device."); |
| 4538 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4539 | final long token = Binder.clearCallingIdentity(); |
| 4540 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4541 | int slotId = getSlotIndexOrException(subId); |
| 4542 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4543 | |
| 4544 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4545 | if (controller != null) { |
| 4546 | ImsManager imsManager = controller.getImsManager(subId); |
| 4547 | if (imsManager != null) { |
| 4548 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4549 | } else { |
| 4550 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4551 | } |
| 4552 | } else { |
| 4553 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4554 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4555 | } catch (ImsException e) { |
| 4556 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4557 | } finally { |
| 4558 | Binder.restoreCallingIdentity(token); |
| 4559 | } |
| 4560 | } |
| 4561 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4562 | /** |
| 4563 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4564 | * @param subId The subscription to use to check the configuration. |
| 4565 | * @param c The callback that will be used to send the result. |
| 4566 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4567 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4568 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4569 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4570 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4571 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4572 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4573 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4574 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4575 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4576 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4577 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4578 | if (controller != null) { |
| 4579 | ImsManager imsManager = controller.getImsManager(subId); |
| 4580 | if (imsManager != null) { |
| 4581 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4582 | } else { |
| 4583 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4584 | + "is inactive, ignoring unregister."); |
| 4585 | // If the ImsManager is not valid, just return, since the callback |
| 4586 | // will already have been removed internally. |
| 4587 | } |
| 4588 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4589 | } finally { |
| 4590 | Binder.restoreCallingIdentity(token); |
| 4591 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4592 | } |
| 4593 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4594 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4595 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4596 | * @param subId The subscription to use to check the configuration. |
| 4597 | * @param c The callback that will be used to send the result. |
| 4598 | */ |
| 4599 | @Override |
| 4600 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4601 | throws RemoteException { |
| 4602 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4603 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4604 | |
| 4605 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4606 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4607 | "IMS not available on device."); |
| 4608 | } |
| 4609 | final long token = Binder.clearCallingIdentity(); |
| 4610 | try { |
| 4611 | int slotId = getSlotIndexOrException(subId); |
| 4612 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4613 | |
| 4614 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4615 | if (controller != null) { |
| 4616 | ImsManager imsManager = controller.getImsManager(subId); |
| 4617 | if (imsManager != null) { |
| 4618 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4619 | } else { |
| 4620 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4621 | } |
| 4622 | } else { |
| 4623 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4624 | } |
| 4625 | } catch (ImsException e) { |
| 4626 | throw new ServiceSpecificException(e.getCode()); |
| 4627 | } finally { |
| 4628 | Binder.restoreCallingIdentity(token); |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | /** |
| 4633 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4634 | * @param subId The subscription to use to check the configuration. |
| 4635 | * @param c The callback that will be used to send the result. |
| 4636 | */ |
| 4637 | @Override |
| 4638 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4639 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4640 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4641 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4642 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4643 | } |
| 4644 | final long token = Binder.clearCallingIdentity(); |
| 4645 | |
| 4646 | try { |
| 4647 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4648 | if (controller != null) { |
| 4649 | ImsManager imsManager = controller.getImsManager(subId); |
| 4650 | if (imsManager != null) { |
| 4651 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4652 | } else { |
| 4653 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4654 | + "is inactive, ignoring unregister."); |
| 4655 | // If the ImsManager is not valid, just return, since the callback |
| 4656 | // will already have been removed internally. |
| 4657 | } |
| 4658 | } |
| 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(token); |
| 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4665 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4666 | */ |
| 4667 | @Override |
| 4668 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4669 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4670 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4671 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4672 | "IMS not available on device."); |
| 4673 | } |
| 4674 | final long token = Binder.clearCallingIdentity(); |
| 4675 | try { |
| 4676 | Phone phone = getPhone(subId); |
| 4677 | if (phone == null) { |
| 4678 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4679 | + subId + "'"); |
| 4680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4681 | } |
| 4682 | phone.getImsRegistrationState(regState -> { |
| 4683 | try { |
| 4684 | consumer.accept((regState == null) |
| 4685 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4686 | } catch (RemoteException e) { |
| 4687 | // Ignore if the remote process is no longer available to call back. |
| 4688 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4689 | } |
| 4690 | }); |
| 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(token); |
| 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | /** |
| 4697 | * Get the transport type for the IMS service registration state. |
| 4698 | */ |
| 4699 | @Override |
| 4700 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4701 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4702 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4703 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4704 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4705 | "IMS not available on device."); |
| 4706 | } |
| 4707 | final long token = Binder.clearCallingIdentity(); |
| 4708 | try { |
| 4709 | Phone phone = getPhone(subId); |
| 4710 | if (phone == null) { |
| 4711 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4712 | + subId + "'"); |
| 4713 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4714 | } |
| 4715 | phone.getImsRegistrationTech(regTech -> { |
| 4716 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4717 | int regTechConverted = (regTech == null) |
| 4718 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4719 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4720 | regTechConverted); |
| 4721 | try { |
| 4722 | consumer.accept(regTechConverted); |
| 4723 | } catch (RemoteException e) { |
| 4724 | // Ignore if the remote process is no longer available to call back. |
| 4725 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4726 | } |
| 4727 | }); |
| 4728 | } finally { |
| 4729 | Binder.restoreCallingIdentity(token); |
| 4730 | } |
| 4731 | } |
| 4732 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4733 | /** |
| 4734 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4735 | * @param subId The subscription to use to check the configuration. |
| 4736 | * @param c The callback that will be used to send the result. |
| 4737 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4738 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4739 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4740 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4741 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4742 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4743 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4744 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4745 | "IMS not available on device."); |
| 4746 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4747 | final long token = Binder.clearCallingIdentity(); |
| 4748 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4749 | int slotId = getSlotIndexOrException(subId); |
| 4750 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4751 | |
| 4752 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4753 | if (controller != null) { |
| 4754 | ImsManager imsManager = controller.getImsManager(subId); |
| 4755 | if (imsManager != null) { |
| 4756 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4757 | } else { |
| 4758 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4759 | } |
| 4760 | } else { |
| 4761 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4762 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4763 | } catch (ImsException e) { |
| 4764 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4765 | } finally { |
| 4766 | Binder.restoreCallingIdentity(token); |
| 4767 | } |
| 4768 | } |
| 4769 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4770 | /** |
| 4771 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4772 | * @param subId The subscription to use to check the configuration. |
| 4773 | * @param c The callback that will be used to send the result. |
| 4774 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4775 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4776 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4777 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4778 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4779 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4780 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4781 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4782 | |
| 4783 | final long token = Binder.clearCallingIdentity(); |
| 4784 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4785 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4786 | if (controller != null) { |
| 4787 | ImsManager imsManager = controller.getImsManager(subId); |
| 4788 | if (imsManager != null) { |
| 4789 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4790 | } else { |
| 4791 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4792 | + " is inactive, ignoring unregister."); |
| 4793 | // If the ImsManager is not valid, just return, since the callback |
| 4794 | // will already have been removed internally. |
| 4795 | } |
| 4796 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4797 | } finally { |
| 4798 | Binder.restoreCallingIdentity(token); |
| 4799 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4803 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4804 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4805 | |
| 4806 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4807 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4808 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4809 | final long token = Binder.clearCallingIdentity(); |
| 4810 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4811 | int slotId = getSlotIndexOrException(subId); |
| 4812 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4813 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4814 | } catch (com.android.ims.ImsException e) { |
| 4815 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4816 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4817 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4818 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4819 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4820 | } finally { |
| 4821 | Binder.restoreCallingIdentity(token); |
| 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4826 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4827 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4828 | |
| 4829 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4830 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4831 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4832 | final long token = Binder.clearCallingIdentity(); |
| 4833 | try { |
| 4834 | Phone phone = getPhone(subId); |
| 4835 | if (phone == null) return false; |
| 4836 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4837 | } catch (com.android.ims.ImsException e) { |
| 4838 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4839 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4840 | } finally { |
| 4841 | Binder.restoreCallingIdentity(token); |
| 4842 | } |
| 4843 | } |
| 4844 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4845 | /** |
| 4846 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4847 | * subscription. |
| 4848 | * @param subId The subscription to use to check the configuration. |
| 4849 | * @param callback The callback that will be used to send the result. |
| 4850 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4851 | * @param transportType The transport type of the MmTelFeature capability. |
| 4852 | */ |
| 4853 | @Override |
| 4854 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4855 | int transportType) { |
| 4856 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4857 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4858 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4859 | "IMS not available on device."); |
| 4860 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4861 | final long token = Binder.clearCallingIdentity(); |
| 4862 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4863 | int slotId = getSlotIndex(subId); |
| 4864 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4865 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4866 | + subId + "'"); |
| 4867 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4868 | } |
| 4869 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4870 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4871 | transportType, aBoolean -> { |
| 4872 | try { |
| 4873 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4874 | } catch (RemoteException e) { |
| 4875 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4876 | + "running. Ignore"); |
| 4877 | } |
| 4878 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4879 | } catch (ImsException e) { |
| 4880 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4881 | } finally { |
| 4882 | Binder.restoreCallingIdentity(token); |
| 4883 | } |
| 4884 | } |
| 4885 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4886 | /** |
| 4887 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4888 | * @param subId The subscription to use to check the configuration. |
| 4889 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4890 | @Override |
| 4891 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4892 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4893 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4894 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4895 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4896 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4897 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4898 | final long token = Binder.clearCallingIdentity(); |
| 4899 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4900 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4901 | // 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] | 4902 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4903 | } catch (ImsException e) { |
| 4904 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4905 | } finally { |
| 4906 | Binder.restoreCallingIdentity(token); |
| 4907 | } |
| 4908 | } |
| 4909 | |
| 4910 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4911 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4913 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4914 | |
| 4915 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4916 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4917 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4918 | final long identity = Binder.clearCallingIdentity(); |
| 4919 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4920 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4921 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4922 | // 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] | 4923 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4924 | } catch (ImsException e) { |
| 4925 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4926 | } finally { |
| 4927 | Binder.restoreCallingIdentity(identity); |
| 4928 | } |
| 4929 | } |
| 4930 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4931 | /** |
| 4932 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4933 | * @param subId The subscription to use to check the configuration. |
| 4934 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4935 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4936 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4937 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4938 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4939 | |
| 4940 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4941 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4942 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4943 | final long identity = Binder.clearCallingIdentity(); |
| 4944 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4945 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4946 | // 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] | 4947 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4948 | } catch (ImsException e) { |
| 4949 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4950 | } finally { |
| 4951 | Binder.restoreCallingIdentity(identity); |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4956 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4958 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4959 | |
| 4960 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4961 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4962 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4963 | final long identity = Binder.clearCallingIdentity(); |
| 4964 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4965 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4966 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4967 | // 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] | 4968 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4969 | } catch (ImsException e) { |
| 4970 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
| 4973 | } |
| 4974 | } |
| 4975 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4976 | /** |
| 4977 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4978 | * @param subId The subscription to use to check the configuration. |
| 4979 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4980 | @Override |
| 4981 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4982 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4983 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4984 | |
| 4985 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4986 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 4987 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4990 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4991 | // 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] | 4992 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4993 | } catch (ImsException e) { |
| 4994 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4995 | } finally { |
| 4996 | Binder.restoreCallingIdentity(identity); |
| 4997 | } |
| 4998 | } |
| 4999 | |
| 5000 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5001 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5003 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5004 | |
| 5005 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5006 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5007 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5008 | final long identity = Binder.clearCallingIdentity(); |
| 5009 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5010 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5011 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5012 | // 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] | 5013 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5014 | } catch (ImsException e) { |
| 5015 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5016 | } finally { |
| 5017 | Binder.restoreCallingIdentity(identity); |
| 5018 | } |
| 5019 | } |
| 5020 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5021 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5022 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5023 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5024 | * @param subId The subscription to use to check the configuration. |
| 5025 | */ |
| 5026 | @Override |
| 5027 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5028 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5029 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5030 | |
| 5031 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5032 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5033 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5034 | final long identity = Binder.clearCallingIdentity(); |
| 5035 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5036 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5037 | // 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] | 5038 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5039 | } catch (ImsException e) { |
| 5040 | throw new ServiceSpecificException(e.getCode()); |
| 5041 | } finally { |
| 5042 | Binder.restoreCallingIdentity(identity); |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | /** |
| 5047 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5048 | * Requires MODIFY_PHONE_STATE permission. |
| 5049 | * @param subId The subscription to use to check the configuration. |
| 5050 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5051 | * false otherwise |
| 5052 | */ |
| 5053 | @Override |
| 5054 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5055 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5056 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5057 | |
| 5058 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5059 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5060 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5061 | final long identity = Binder.clearCallingIdentity(); |
| 5062 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5063 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5064 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5065 | // 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] | 5066 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5067 | } catch (ImsException e) { |
| 5068 | throw new ServiceSpecificException(e.getCode()); |
| 5069 | } finally { |
| 5070 | Binder.restoreCallingIdentity(identity); |
| 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5075 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5076 | * @param subId The subscription to use to check the configuration. |
| 5077 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5078 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5079 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5080 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5081 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5082 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5083 | |
| 5084 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5085 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5086 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5087 | final long identity = Binder.clearCallingIdentity(); |
| 5088 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5089 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5090 | // 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] | 5091 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5092 | } catch (ImsException e) { |
| 5093 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5094 | } finally { |
| 5095 | Binder.restoreCallingIdentity(identity); |
| 5096 | } |
| 5097 | } |
| 5098 | |
| 5099 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5100 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5102 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5103 | |
| 5104 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5105 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5106 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5107 | final long identity = Binder.clearCallingIdentity(); |
| 5108 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5109 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5110 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5111 | // 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] | 5112 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5113 | } catch (ImsException e) { |
| 5114 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5115 | } finally { |
| 5116 | Binder.restoreCallingIdentity(identity); |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | @Override |
| 5121 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5123 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5124 | |
| 5125 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5126 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5127 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5128 | final long identity = Binder.clearCallingIdentity(); |
| 5129 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5130 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5131 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5132 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5133 | } catch (ImsException e) { |
| 5134 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
| 5137 | } |
| 5138 | } |
| 5139 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5140 | /** |
| 5141 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5142 | * @param subId The subscription to use to check the configuration. |
| 5143 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5144 | @Override |
| 5145 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5146 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5147 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5148 | |
| 5149 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5150 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5151 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5152 | final long identity = Binder.clearCallingIdentity(); |
| 5153 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5154 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5155 | // 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] | 5156 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5157 | } catch (ImsException e) { |
| 5158 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5159 | } finally { |
| 5160 | Binder.restoreCallingIdentity(identity); |
| 5161 | } |
| 5162 | } |
| 5163 | |
| 5164 | @Override |
| 5165 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5167 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5168 | |
| 5169 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5170 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5171 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5172 | final long identity = Binder.clearCallingIdentity(); |
| 5173 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5174 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5175 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5176 | // 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] | 5177 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5178 | } catch (ImsException e) { |
| 5179 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5180 | } finally { |
| 5181 | Binder.restoreCallingIdentity(identity); |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | @Override |
| 5186 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5187 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5188 | |
| 5189 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5190 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5191 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5194 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5195 | // 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] | 5196 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5197 | } catch (ImsException e) { |
| 5198 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
| 5202 | } |
| 5203 | |
| 5204 | @Override |
| 5205 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5206 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5207 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5208 | |
| 5209 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5210 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5211 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5212 | final long identity = Binder.clearCallingIdentity(); |
| 5213 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5214 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5215 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5216 | // 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] | 5217 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5218 | } catch (ImsException e) { |
| 5219 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5220 | } finally { |
| 5221 | Binder.restoreCallingIdentity(identity); |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | @Override |
| 5226 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5227 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5228 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5229 | |
| 5230 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5231 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5232 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5233 | final long identity = Binder.clearCallingIdentity(); |
| 5234 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5235 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5236 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5237 | // 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] | 5238 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5239 | } catch (ImsException e) { |
| 5240 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5241 | } finally { |
| 5242 | Binder.restoreCallingIdentity(identity); |
| 5243 | } |
| 5244 | } |
| 5245 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5246 | /** |
| 5247 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5248 | * @param subId The subscription to use to check the configuration. |
| 5249 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5250 | @Override |
| 5251 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5252 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5253 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5254 | |
| 5255 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5256 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5257 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5258 | final long identity = Binder.clearCallingIdentity(); |
| 5259 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5260 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5261 | // 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] | 5262 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5263 | } catch (ImsException e) { |
| 5264 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5265 | } finally { |
| 5266 | Binder.restoreCallingIdentity(identity); |
| 5267 | } |
| 5268 | } |
| 5269 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5270 | @Override |
| 5271 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5272 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5273 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5274 | final long identity = Binder.clearCallingIdentity(); |
| 5275 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5276 | if (!isImsAvailableOnDevice()) { |
| 5277 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5278 | "IMS not available on device."); |
| 5279 | } |
| 5280 | int slotId = getSlotIndexOrException(subId); |
| 5281 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5282 | |
| 5283 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5284 | if (controller != null) { |
| 5285 | ImsManager imsManager = controller.getImsManager(subId); |
| 5286 | if (imsManager != null) { |
| 5287 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5288 | } else { |
| 5289 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5290 | } |
| 5291 | } else { |
| 5292 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5293 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5294 | } catch (ImsException e) { |
| 5295 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5296 | } finally { |
| 5297 | Binder.restoreCallingIdentity(identity); |
| 5298 | } |
| 5299 | } |
| 5300 | |
| 5301 | @Override |
| 5302 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5303 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
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(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5306 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5307 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5308 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5309 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5310 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5311 | if (controller != null) { |
| 5312 | ImsManager imsManager = controller.getImsManager(subId); |
| 5313 | if (imsManager != null) { |
| 5314 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5315 | } else { |
| 5316 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5317 | + " is inactive, ignoring unregister."); |
| 5318 | // If the ImsManager is not valid, just return, since the callback will already |
| 5319 | // have been removed internally. |
| 5320 | } |
| 5321 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5322 | } finally { |
| 5323 | Binder.restoreCallingIdentity(identity); |
| 5324 | } |
| 5325 | } |
| 5326 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5327 | @Override |
| 5328 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5329 | IFeatureProvisioningCallback callback) { |
| 5330 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5331 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5332 | |
| 5333 | final long identity = Binder.clearCallingIdentity(); |
| 5334 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5335 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5336 | } |
| 5337 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5338 | try { |
| 5339 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5340 | if (controller == null) { |
| 5341 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5342 | "Device does not support IMS"); |
| 5343 | } |
| 5344 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(identity); |
| 5347 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | @Override |
| 5351 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5352 | IFeatureProvisioningCallback callback) { |
| 5353 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5354 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5355 | |
| 5356 | final long identity = Binder.clearCallingIdentity(); |
| 5357 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5358 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5359 | } |
| 5360 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5361 | try { |
| 5362 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5363 | if (controller == null) { |
| 5364 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5365 | return; |
| 5366 | } |
| 5367 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5368 | } finally { |
| 5369 | Binder.restoreCallingIdentity(identity); |
| 5370 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5371 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5372 | |
| 5373 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5375 | message); |
| 5376 | } |
| 5377 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5378 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5379 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5380 | boolean isProvisioned) { |
| 5381 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5382 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5383 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5384 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5385 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5386 | final long identity = Binder.clearCallingIdentity(); |
| 5387 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5388 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5389 | if (controller == null) { |
| 5390 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5391 | return; |
| 5392 | } |
| 5393 | controller.setRcsProvisioningStatusForCapability( |
| 5394 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5395 | } finally { |
| 5396 | Binder.restoreCallingIdentity(identity); |
| 5397 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | |
| 5401 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5402 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5403 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5404 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5405 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5406 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5407 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5408 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5409 | final long identity = Binder.clearCallingIdentity(); |
| 5410 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5411 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5412 | if (controller == null) { |
| 5413 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5414 | |
| 5415 | // device does not support IMS, this method will return true always. |
| 5416 | return true; |
| 5417 | } |
| 5418 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5419 | } finally { |
| 5420 | Binder.restoreCallingIdentity(identity); |
| 5421 | } |
| 5422 | } |
| 5423 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5424 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5425 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5426 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5427 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5428 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5429 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5430 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5431 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5432 | final long identity = Binder.clearCallingIdentity(); |
| 5433 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5434 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5435 | if (controller == null) { |
| 5436 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5437 | return; |
| 5438 | } |
| 5439 | controller.setImsProvisioningStatusForCapability( |
| 5440 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | @Override |
| 5447 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5448 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5449 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5450 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5451 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5452 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5453 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5454 | final long identity = Binder.clearCallingIdentity(); |
| 5455 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5456 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5457 | if (controller == null) { |
| 5458 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5459 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5460 | // device does not support IMS, this method will return true always. |
| 5461 | return true; |
| 5462 | } |
| 5463 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5464 | } finally { |
| 5465 | Binder.restoreCallingIdentity(identity); |
| 5466 | } |
| 5467 | } |
| 5468 | |
| 5469 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5470 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5471 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5472 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5473 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5474 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5475 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5476 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5479 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5480 | if (controller == null) { |
| 5481 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5482 | |
| 5483 | // device does not support IMS, this method will return false |
| 5484 | return false; |
| 5485 | } |
| 5486 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5489 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5493 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5494 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5495 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5496 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5497 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5498 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5499 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5500 | final long identity = Binder.clearCallingIdentity(); |
| 5501 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5502 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5503 | if (controller == null) { |
| 5504 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5505 | |
| 5506 | // device does not support IMS, this method will return false |
| 5507 | return false; |
| 5508 | } |
| 5509 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5510 | } finally { |
| 5511 | Binder.restoreCallingIdentity(identity); |
| 5512 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5513 | } |
| 5514 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5515 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5516 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5517 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5518 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5519 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5520 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5521 | mApp, subId, "getImsProvisioningInt"); |
| 5522 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5523 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5524 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5525 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5526 | final long identity = Binder.clearCallingIdentity(); |
| 5527 | try { |
| 5528 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5529 | int slotId = getSlotIndex(subId); |
| 5530 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5531 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5532 | + subId + "' for key:" + key); |
| 5533 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5534 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5535 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5536 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5537 | if (controller == null) { |
| 5538 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5539 | |
| 5540 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5541 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5542 | } |
| 5543 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5544 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5545 | return retVal; |
| 5546 | } |
| 5547 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5548 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5549 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5550 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5551 | + subId + "' for key:" + key); |
| 5552 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5553 | } finally { |
| 5554 | Binder.restoreCallingIdentity(identity); |
| 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | @Override |
| 5559 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5560 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5561 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5562 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5563 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5564 | mApp, subId, "getImsProvisioningString"); |
| 5565 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5566 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5567 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5568 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5569 | final long identity = Binder.clearCallingIdentity(); |
| 5570 | try { |
| 5571 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5572 | int slotId = getSlotIndex(subId); |
| 5573 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5574 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5575 | + subId + "' for key:" + key); |
| 5576 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5577 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5578 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5579 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5580 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5581 | + subId + "' for key:" + key); |
| 5582 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5583 | } finally { |
| 5584 | Binder.restoreCallingIdentity(identity); |
| 5585 | } |
| 5586 | } |
| 5587 | |
| 5588 | @Override |
| 5589 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5590 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5591 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5592 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5593 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5594 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5595 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5596 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5597 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5598 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5599 | final long identity = Binder.clearCallingIdentity(); |
| 5600 | try { |
| 5601 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5602 | int slotId = getSlotIndex(subId); |
| 5603 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5604 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5605 | + subId + "' for key:" + key); |
| 5606 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5607 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5608 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5609 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5610 | if (controller == null) { |
| 5611 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5612 | |
| 5613 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5614 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5615 | } |
| 5616 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5617 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5618 | return retVal; |
| 5619 | } |
| 5620 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5621 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5622 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5623 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5624 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5625 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
| 5628 | } |
| 5629 | } |
| 5630 | |
| 5631 | @Override |
| 5632 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5633 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5634 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5635 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5637 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5638 | |
| 5639 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5640 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5641 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5642 | final long identity = Binder.clearCallingIdentity(); |
| 5643 | try { |
| 5644 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5645 | int slotId = getSlotIndex(subId); |
| 5646 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5647 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5648 | + subId + "' for key:" + key); |
| 5649 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5650 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5651 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5652 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5653 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5654 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5655 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5656 | } finally { |
| 5657 | Binder.restoreCallingIdentity(identity); |
| 5658 | } |
| 5659 | } |
| 5660 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5661 | /** |
| 5662 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5663 | * for the given slot ID or no ImsResolver instance has been created. |
| 5664 | * @param slotId The slot ID that the IMS service is created for. |
| 5665 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5666 | */ |
| 5667 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5668 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5669 | ImsFeature.FEATURE_MMTEL)) { |
| 5670 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5671 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5672 | } |
| 5673 | } |
| 5674 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5675 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5676 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5677 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5678 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5679 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5680 | } |
| 5681 | return slotId; |
| 5682 | } |
| 5683 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5684 | private int getSlotIndex(int subId) { |
| 5685 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5686 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5687 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5688 | } |
| 5689 | return slotId; |
| 5690 | } |
| 5691 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5692 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5693 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5694 | */ |
| 5695 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5696 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5697 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5698 | try { |
| 5699 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5700 | } catch (SecurityException se) { |
| 5701 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5702 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5703 | + Binder.getCallingUid()); |
| 5704 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5705 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5706 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5707 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5708 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5709 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5710 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5711 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5712 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5713 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5714 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5715 | enforceTelephonyFeatureWithException(callingPackage, |
| 5716 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5718 | final long identity = Binder.clearCallingIdentity(); |
| 5719 | try { |
| 5720 | final Phone phone = getPhone(subId); |
| 5721 | if (phone != null) { |
| 5722 | return phone.getServiceState().getDataNetworkType(); |
| 5723 | } else { |
| 5724 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5725 | } |
| 5726 | } finally { |
| 5727 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | /** |
| 5732 | * Returns the data network type |
| 5733 | */ |
| 5734 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5735 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5736 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5737 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | /** |
| 5741 | * Returns the data network type for a subId |
| 5742 | */ |
| 5743 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5744 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5745 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5746 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5747 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5748 | mApp, functionName)) { |
| 5749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5750 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5751 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5752 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5753 | } |
| 5754 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5755 | enforceTelephonyFeatureWithException(callingPackage, |
| 5756 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5757 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5758 | final long identity = Binder.clearCallingIdentity(); |
| 5759 | try { |
| 5760 | final Phone phone = getPhone(subId); |
| 5761 | if (phone != null) { |
| 5762 | return phone.getServiceState().getDataNetworkType(); |
| 5763 | } else { |
| 5764 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5765 | } |
| 5766 | } finally { |
| 5767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5772 | * Returns the Voice network type for a subId |
| 5773 | */ |
| 5774 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5775 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5776 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5777 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 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 | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5786 | enforceTelephonyFeatureWithException(callingPackage, |
| 5787 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 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().getVoiceNetworkType(); |
| 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 | /** |
| 5803 | * @return true if a ICC card is present |
| 5804 | */ |
| 5805 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5806 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5807 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5808 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5812 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5813 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5814 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5815 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5816 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5817 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5818 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5819 | final long identity = Binder.clearCallingIdentity(); |
| 5820 | try { |
| 5821 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5822 | if (phone != null) { |
| 5823 | return phone.getIccCard().hasIccCard(); |
| 5824 | } else { |
| 5825 | return false; |
| 5826 | } |
| 5827 | } finally { |
| 5828 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5829 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | /** |
| 5833 | * Return if the current radio is LTE on CDMA. This |
| 5834 | * is a tri-state return value as for a period of time |
| 5835 | * the mode may be unknown. |
| 5836 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5837 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5838 | * @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] | 5839 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5840 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5841 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5842 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5843 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5844 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5845 | } |
| 5846 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5847 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5848 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5849 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5850 | try { |
| 5851 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5852 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5853 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5854 | } |
| 5855 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5856 | enforceTelephonyFeatureWithException(callingPackage, |
| 5857 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5858 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5859 | final long identity = Binder.clearCallingIdentity(); |
| 5860 | try { |
| 5861 | final Phone phone = getPhone(subId); |
| 5862 | if (phone == null) { |
| 5863 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5864 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5865 | return TelephonyProperties.lte_on_cdma_device() |
| 5866 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5867 | } |
| 5868 | } finally { |
| 5869 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5870 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5871 | } |
| 5872 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5873 | /** |
| 5874 | * {@hide} |
| 5875 | * Returns Default subId, 0 in the case of single standby. |
| 5876 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5877 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5878 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5879 | } |
| 5880 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5881 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5882 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5883 | } |
| 5884 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5885 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5886 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5887 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5888 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5889 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5890 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5891 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5894 | /** |
| 5895 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5896 | */ |
| 5897 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5898 | final long identity = Binder.clearCallingIdentity(); |
| 5899 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5900 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5901 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5902 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
| 5905 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | /** |
| 5909 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5910 | */ |
| 5911 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5912 | final long identity = Binder.clearCallingIdentity(); |
| 5913 | try { |
| 5914 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5915 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5917 | } finally { |
| 5918 | Binder.restoreCallingIdentity(identity); |
| 5919 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5920 | } |
| 5921 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5922 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5923 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5924 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5925 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5926 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5927 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5928 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5929 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5930 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5931 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5932 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5933 | } |
| 5934 | return PhoneFactory.getPhone(phoneId); |
| 5935 | } |
| 5936 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5937 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5938 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5939 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5940 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5941 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5942 | /*message=*/ "iccOpenLogicalChannel"); |
| 5943 | |
| 5944 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5945 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5946 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5947 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5948 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5949 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5950 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5951 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5952 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5953 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5954 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5955 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5956 | Phone phone; |
| 5957 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5959 | mApp, request.subId, message); |
| 5960 | phone = getPhoneFromSubId(request.subId); |
| 5961 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5962 | enforceModifyPermission(); |
| 5963 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5964 | } else { |
| 5965 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5966 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5967 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5971 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5972 | final long identity = Binder.clearCallingIdentity(); |
| 5973 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5974 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5976 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5977 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5978 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5979 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5980 | loge("The calling package is not allowed to access ISD-R."); |
| 5981 | throw new SecurityException( |
| 5982 | "The calling package is not allowed to access ISD-R."); |
| 5983 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5984 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5986 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5987 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5988 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5989 | return response; |
| 5990 | } finally { |
| 5991 | Binder.restoreCallingIdentity(identity); |
| 5992 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5993 | } |
| 5994 | |
| 5995 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5996 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5997 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5998 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 5999 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6000 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6001 | /*message=*/"iccCloseLogicalChannel"); |
| 6002 | |
| 6003 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6004 | |
| 6005 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6006 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6007 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6008 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6009 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6010 | // before this feature is enabled, this API should only return false if |
| 6011 | // the operation fails instead of throwing runtime exception for |
| 6012 | // backward-compatibility. |
| 6013 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6014 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 | final long identity = Binder.clearCallingIdentity(); |
| 6016 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6017 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6018 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6020 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6021 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6022 | Boolean success = false; |
| 6023 | if (result instanceof RuntimeException) { |
| 6024 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6025 | if (shouldThrowExceptionOnFailure) { |
| 6026 | throw (RuntimeException) result; |
| 6027 | } else { |
| 6028 | return false; |
| 6029 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6030 | } else if (result instanceof Boolean) { |
| 6031 | success = (Boolean) result; |
| 6032 | } else { |
| 6033 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6034 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6035 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | return success; |
| 6037 | } finally { |
| 6038 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6039 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6043 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6044 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6045 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6046 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6047 | |
| 6048 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6049 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6050 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6051 | if (DBG) { |
| 6052 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6053 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6054 | + p3 + " data=" + data); |
| 6055 | } |
| 6056 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6057 | command, p1, p2, p3, data); |
| 6058 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6059 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6060 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6061 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6062 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6063 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6064 | |
| 6065 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6066 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6067 | "iccTransmitApduLogicalChannelBySlot"); |
| 6068 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6069 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6070 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6071 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6072 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6073 | } |
| 6074 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6075 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6076 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6080 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | final long identity = Binder.clearCallingIdentity(); |
| 6082 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6083 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | return ""; |
| 6085 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6086 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6088 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6089 | null /* workSource */); |
| 6090 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6091 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6092 | // Append the returned status code to the end of the response payload. |
| 6093 | String s = Integer.toHexString( |
| 6094 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6095 | if (response.payload != null) { |
| 6096 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6097 | } |
| 6098 | return s; |
| 6099 | } finally { |
| 6100 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6101 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6102 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6103 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6104 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6105 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6106 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6108 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6110 | |
| 6111 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6112 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6113 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6114 | if (DBG) { |
| 6115 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6116 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6117 | } |
| 6118 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6119 | cla, command, p1, p2, p3, data); |
| 6120 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6121 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6122 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6123 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6124 | 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] | 6125 | enforceModifyPermission(); |
| 6126 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6127 | |
| 6128 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6129 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6130 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6131 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6132 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6133 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6134 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6138 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6139 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6143 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6144 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | final long identity = Binder.clearCallingIdentity(); |
| 6146 | try { |
| 6147 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6148 | && TextUtils.equals(ISDR_AID, data)) { |
| 6149 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6150 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6151 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6152 | if (bestComponent == null |
| 6153 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6154 | loge("The calling package is not allowed to select ISD-R."); |
| 6155 | throw new SecurityException( |
| 6156 | "The calling package is not allowed to select ISD-R."); |
| 6157 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6158 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6159 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6160 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6161 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6162 | null /* workSource */); |
| 6163 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | // Append the returned status code to the end of the response payload. |
| 6166 | String s = Integer.toHexString( |
| 6167 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6168 | if (response.payload != null) { |
| 6169 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6170 | } |
| 6171 | return s; |
| 6172 | } finally { |
| 6173 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6174 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6178 | 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] | 6179 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6181 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6182 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6183 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6184 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6185 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6186 | final long identity = Binder.clearCallingIdentity(); |
| 6187 | try { |
| 6188 | if (DBG) { |
| 6189 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6190 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6191 | } |
| 6192 | |
| 6193 | IccIoResult response = |
| 6194 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6195 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6196 | subId); |
| 6197 | |
| 6198 | if (DBG) { |
| 6199 | log("Exchange SIM_IO [R]" + response); |
| 6200 | } |
| 6201 | |
| 6202 | byte[] result = null; |
| 6203 | int length = 2; |
| 6204 | if (response.payload != null) { |
| 6205 | length = 2 + response.payload.length; |
| 6206 | result = new byte[length]; |
| 6207 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6208 | } else { |
| 6209 | result = new byte[length]; |
| 6210 | } |
| 6211 | |
| 6212 | result[length - 1] = (byte) response.sw2; |
| 6213 | result[length - 2] = (byte) response.sw1; |
| 6214 | return result; |
| 6215 | } finally { |
| 6216 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6217 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6218 | } |
| 6219 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6220 | /** |
| 6221 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6222 | * on a particular subscription |
| 6223 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6224 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6225 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6226 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6227 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6228 | return null; |
| 6229 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6230 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6231 | enforceTelephonyFeatureWithException(callingPackage, |
| 6232 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6233 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6234 | final long identity = Binder.clearCallingIdentity(); |
| 6235 | try { |
| 6236 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6237 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6238 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6239 | return null; |
| 6240 | } |
| 6241 | Object response = sendRequest( |
| 6242 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6243 | if (response instanceof String[]) { |
| 6244 | return (String[]) response; |
| 6245 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6246 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6247 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6248 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6249 | } finally { |
| 6250 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6251 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6252 | } |
| 6253 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6254 | /** |
| 6255 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6256 | * subscription. |
| 6257 | * |
| 6258 | * @param subId the id of the subscription. |
| 6259 | * @param appType the uicc app type, must be USIM or SIM. |
| 6260 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6261 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6262 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6263 | * @return number of fplmns that is successfully written to the SIM. |
| 6264 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6265 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6266 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6268 | mApp, subId, "setForbiddenPlmns"); |
| 6269 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6270 | enforceTelephonyFeatureWithException(callingPackage, |
| 6271 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6272 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6273 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6274 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6275 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6276 | } |
| 6277 | if (fplmns == null) { |
| 6278 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6279 | } |
| 6280 | for (String fplmn : fplmns) { |
| 6281 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6282 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6283 | } |
| 6284 | } |
| 6285 | final long identity = Binder.clearCallingIdentity(); |
| 6286 | try { |
| 6287 | Object response = sendRequest( |
| 6288 | CMD_SET_FORBIDDEN_PLMNS, |
| 6289 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6290 | subId); |
| 6291 | return (int) response; |
| 6292 | } finally { |
| 6293 | Binder.restoreCallingIdentity(identity); |
| 6294 | } |
| 6295 | } |
| 6296 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6297 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6298 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6300 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6301 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6302 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6303 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6304 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6305 | final long identity = Binder.clearCallingIdentity(); |
| 6306 | try { |
| 6307 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6308 | if (response.payload == null) { |
| 6309 | return ""; |
| 6310 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6311 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6312 | // Append the returned status code to the end of the response payload. |
| 6313 | String s = Integer.toHexString( |
| 6314 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6315 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6316 | return s; |
| 6317 | } finally { |
| 6318 | Binder.restoreCallingIdentity(identity); |
| 6319 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6320 | } |
| 6321 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6322 | /** |
| 6323 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6324 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6325 | * |
| 6326 | * @param itemID the ID of the item to read |
| 6327 | * @return the NV item as a String, or null on error. |
| 6328 | */ |
| 6329 | @Override |
| 6330 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6331 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6332 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6333 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | |
| 6335 | final long identity = Binder.clearCallingIdentity(); |
| 6336 | try { |
| 6337 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6338 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6339 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6340 | return value; |
| 6341 | } finally { |
| 6342 | Binder.restoreCallingIdentity(identity); |
| 6343 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6344 | } |
| 6345 | |
| 6346 | /** |
| 6347 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6348 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6349 | * |
| 6350 | * @param itemID the ID of the item to read |
| 6351 | * @param itemValue the value to write, as a String |
| 6352 | * @return true on success; false on any failure |
| 6353 | */ |
| 6354 | @Override |
| 6355 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6356 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6357 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6358 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | |
| 6360 | final long identity = Binder.clearCallingIdentity(); |
| 6361 | try { |
| 6362 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6363 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6364 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6366 | return success; |
| 6367 | } finally { |
| 6368 | Binder.restoreCallingIdentity(identity); |
| 6369 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6370 | } |
| 6371 | |
| 6372 | /** |
| 6373 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6374 | * Used for device configuration by some CDMA operators. |
| 6375 | * |
| 6376 | * @param preferredRoamingList byte array containing the new PRL |
| 6377 | * @return true on success; false on any failure |
| 6378 | */ |
| 6379 | @Override |
| 6380 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6382 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6383 | |
| 6384 | final long identity = Binder.clearCallingIdentity(); |
| 6385 | try { |
| 6386 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6387 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6388 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6389 | return success; |
| 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
| 6392 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6396 | * 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] | 6397 | * Used for device configuration by some CDMA operators. |
| 6398 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6399 | * @param slotIndex - device slot. |
| 6400 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6401 | * @return true on success; false on any failure |
| 6402 | */ |
| 6403 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6404 | public boolean resetModemConfig(int slotIndex) { |
| 6405 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6406 | if (phone != null) { |
| 6407 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6408 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6409 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6410 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6411 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6412 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6413 | final long identity = Binder.clearCallingIdentity(); |
| 6414 | try { |
| 6415 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6416 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6417 | return success; |
| 6418 | } finally { |
| 6419 | Binder.restoreCallingIdentity(identity); |
| 6420 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6422 | return false; |
| 6423 | } |
| 6424 | |
| 6425 | /** |
| 6426 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6427 | * |
| 6428 | * @param slotIndex - device slot. |
| 6429 | * |
| 6430 | * @return true on success; false on any failure |
| 6431 | */ |
| 6432 | @Override |
| 6433 | public boolean rebootModem(int slotIndex) { |
| 6434 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6435 | if (phone != null) { |
| 6436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6437 | mApp, phone.getSubId(), "rebootModem"); |
| 6438 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6439 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6440 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6441 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6445 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6446 | return success; |
| 6447 | } finally { |
| 6448 | Binder.restoreCallingIdentity(identity); |
| 6449 | } |
| 6450 | } |
| 6451 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6452 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6453 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6454 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6455 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6456 | * {@link #disableIms(int)}. |
| 6457 | * @param slotIndex device slot. |
| 6458 | */ |
| 6459 | public void resetIms(int slotIndex) { |
| 6460 | enforceModifyPermission(); |
| 6461 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6462 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6463 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6464 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6465 | final long identity = Binder.clearCallingIdentity(); |
| 6466 | try { |
| 6467 | if (mImsResolver == null) { |
| 6468 | // may happen if the does not support IMS. |
| 6469 | return; |
| 6470 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6471 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6472 | } finally { |
| 6473 | Binder.restoreCallingIdentity(identity); |
| 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6478 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6479 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6480 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6481 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6482 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6483 | |
| 6484 | final long identity = Binder.clearCallingIdentity(); |
| 6485 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6486 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6487 | // may happen if the device does not support IMS. |
| 6488 | return; |
| 6489 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6490 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6491 | } finally { |
| 6492 | Binder.restoreCallingIdentity(identity); |
| 6493 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6494 | } |
| 6495 | |
| 6496 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6497 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6498 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6499 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6500 | public void disableIms(int slotId) { |
| 6501 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6502 | |
| 6503 | final long identity = Binder.clearCallingIdentity(); |
| 6504 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6505 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6506 | // may happen if the device does not support IMS. |
| 6507 | return; |
| 6508 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6509 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6510 | } finally { |
| 6511 | Binder.restoreCallingIdentity(identity); |
| 6512 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6516 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6517 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6518 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6519 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6520 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6521 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6522 | |
| 6523 | final long identity = Binder.clearCallingIdentity(); |
| 6524 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6525 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6526 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6527 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6528 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6529 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(identity); |
| 6532 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6533 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6534 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6535 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6536 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6537 | @Override |
| 6538 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6539 | enforceModifyPermission(); |
| 6540 | |
| 6541 | final long identity = Binder.clearCallingIdentity(); |
| 6542 | try { |
| 6543 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6544 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6545 | } finally { |
| 6546 | Binder.restoreCallingIdentity(identity); |
| 6547 | } |
| 6548 | } |
| 6549 | |
| 6550 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6551 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6552 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6553 | */ |
| 6554 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6555 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6556 | |
| 6557 | final long identity = Binder.clearCallingIdentity(); |
| 6558 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6559 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6560 | // may happen if the device does not support IMS. |
| 6561 | return null; |
| 6562 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6563 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | } finally { |
| 6565 | Binder.restoreCallingIdentity(identity); |
| 6566 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6567 | } |
| 6568 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6569 | /** |
| 6570 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6571 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6572 | */ |
| 6573 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6574 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6575 | |
| 6576 | final long identity = Binder.clearCallingIdentity(); |
| 6577 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6578 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6579 | // may happen if the device does not support IMS. |
| 6580 | return null; |
| 6581 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6582 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | } finally { |
| 6584 | Binder.restoreCallingIdentity(identity); |
| 6585 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6586 | } |
| 6587 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6588 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6589 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6590 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6591 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6592 | * @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] | 6593 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6594 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6595 | * @param packageName The name of the package that the current configuration will be replaced |
| 6596 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6597 | * @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] | 6598 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6599 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6600 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6601 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6603 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6604 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6605 | final long identity = Binder.clearCallingIdentity(); |
| 6606 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6607 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6608 | // may happen if the device does not support IMS. |
| 6609 | return false; |
| 6610 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6611 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6612 | for (int featureType : featureTypes) { |
| 6613 | featureConfig.put(featureType, packageName); |
| 6614 | } |
| 6615 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6616 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | } finally { |
| 6618 | Binder.restoreCallingIdentity(identity); |
| 6619 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6620 | } |
| 6621 | |
| 6622 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6623 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6624 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6625 | * |
| 6626 | * This should only be used for testing. |
| 6627 | * |
| 6628 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6629 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6630 | */ |
| 6631 | @Override |
| 6632 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6633 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6634 | "clearCarrierImsServiceOverride"); |
| 6635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6636 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6637 | |
| 6638 | final long identity = Binder.clearCallingIdentity(); |
| 6639 | try { |
| 6640 | if (mImsResolver == null) { |
| 6641 | // may happen if the device does not support IMS. |
| 6642 | return false; |
| 6643 | } |
| 6644 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6645 | } finally { |
| 6646 | Binder.restoreCallingIdentity(identity); |
| 6647 | } |
| 6648 | } |
| 6649 | |
| 6650 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6651 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6652 | * |
| 6653 | * @param slotId The slot that the ImsService is associated with. |
| 6654 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6655 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6656 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6657 | * @return the package name of the ImsService configuration. |
| 6658 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6659 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6660 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6661 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6662 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6663 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6664 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6665 | final long identity = Binder.clearCallingIdentity(); |
| 6666 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6667 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6668 | // may happen if the device does not support IMS. |
| 6669 | return ""; |
| 6670 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6671 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6672 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6673 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6674 | } finally { |
| 6675 | Binder.restoreCallingIdentity(identity); |
| 6676 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6677 | } |
| 6678 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6679 | /** |
| 6680 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6681 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6682 | * @param callback A callback with an integer containing the |
| 6683 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6684 | */ |
| 6685 | @Override |
| 6686 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6687 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6688 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6689 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6690 | "IMS not available on device."); |
| 6691 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6692 | final long token = Binder.clearCallingIdentity(); |
| 6693 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6694 | int slotId = getSlotIndex(subId); |
| 6695 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6696 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6697 | + subId + "'"); |
| 6698 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6699 | } |
| 6700 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6701 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6702 | try { |
| 6703 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6704 | } catch (RemoteException e) { |
| 6705 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6706 | + "Ignore"); |
| 6707 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6708 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6709 | } catch (ImsException e) { |
| 6710 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6711 | } finally { |
| 6712 | Binder.restoreCallingIdentity(token); |
| 6713 | } |
| 6714 | } |
| 6715 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6716 | /** |
| 6717 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6718 | */ |
| 6719 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6720 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6721 | |
| 6722 | final long identity = Binder.clearCallingIdentity(); |
| 6723 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6724 | // NOTE: Before S, this method only set the default phone. |
| 6725 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6726 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6727 | phone.setImsRegistrationState(registered); |
| 6728 | } |
| 6729 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6730 | } finally { |
| 6731 | Binder.restoreCallingIdentity(identity); |
| 6732 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6733 | } |
| 6734 | |
| 6735 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6736 | * Set the network selection mode to automatic. |
| 6737 | * |
| 6738 | */ |
| 6739 | @Override |
| 6740 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6741 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6742 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6743 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6744 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6745 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6747 | final long identity = Binder.clearCallingIdentity(); |
| 6748 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6749 | if (!isActiveSubscription(subId)) { |
| 6750 | return; |
| 6751 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6752 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6753 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6754 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6755 | } finally { |
| 6756 | Binder.restoreCallingIdentity(identity); |
| 6757 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6758 | } |
| 6759 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6760 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6761 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6762 | * |
| 6763 | * @param subId the id of the subscription. |
| 6764 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6765 | * the operator to attach to. |
| 6766 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6767 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6768 | * normal network selection next time. |
| 6769 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6770 | */ |
| 6771 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6772 | public boolean setNetworkSelectionModeManual( |
| 6773 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6775 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6776 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6777 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6778 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6779 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6780 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6781 | if (!isActiveSubscription(subId)) { |
| 6782 | return false; |
| 6783 | } |
| 6784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6785 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6786 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6787 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6788 | if (DBG) { |
| 6789 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6790 | + " operator: " + operatorInfo); |
| 6791 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6792 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
| 6795 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6796 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6797 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6798 | * Get the manual network selection |
| 6799 | * |
| 6800 | * @param subId the id of the subscription. |
| 6801 | * |
| 6802 | * @return the previously saved user selected PLMN |
| 6803 | */ |
| 6804 | @Override |
| 6805 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6806 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6807 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6808 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6809 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6810 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6811 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6812 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6813 | final long identity = Binder.clearCallingIdentity(); |
| 6814 | try { |
| 6815 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6816 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
| 6819 | final Phone phone = getPhone(subId); |
| 6820 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6821 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6822 | } |
| 6823 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6824 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6825 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6826 | } finally { |
| 6827 | Binder.restoreCallingIdentity(identity); |
| 6828 | } |
| 6829 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6830 | |
| 6831 | /** |
| 6832 | * Scans for available networks. |
| 6833 | */ |
| 6834 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6835 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6836 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6837 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6838 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6839 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6840 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6841 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6842 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6843 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6844 | .setCallingPid(Binder.getCallingPid()) |
| 6845 | .setCallingUid(Binder.getCallingUid()) |
| 6846 | .setMethod("getCellNetworkScanResults") |
| 6847 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6848 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6849 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6850 | .build()); |
| 6851 | switch (locationResult) { |
| 6852 | case DENIED_HARD: |
| 6853 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6854 | case DENIED_SOFT: |
| 6855 | return null; |
| 6856 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6857 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6858 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6859 | try { |
| 6860 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6861 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6862 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6863 | } finally { |
| 6864 | Binder.restoreCallingIdentity(identity); |
| 6865 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6866 | } |
| 6867 | |
| 6868 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6869 | * Get the call forwarding info, given the call forwarding reason. |
| 6870 | */ |
| 6871 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6872 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6873 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6874 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6875 | |
| 6876 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6877 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6878 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6879 | long identity = Binder.clearCallingIdentity(); |
| 6880 | try { |
| 6881 | if (DBG) { |
| 6882 | log("getCallForwarding: subId " + subId |
| 6883 | + " callForwardingReason" + callForwardingReason); |
| 6884 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6885 | |
| 6886 | Phone phone = getPhone(subId); |
| 6887 | if (phone == null) { |
| 6888 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6889 | callback.onError( |
| 6890 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6891 | } catch (RemoteException e) { |
| 6892 | // ignore |
| 6893 | } |
| 6894 | return; |
| 6895 | } |
| 6896 | |
| 6897 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6898 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6899 | @Override |
| 6900 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6901 | try { |
| 6902 | callback.onCallForwardingInfoAvailable(info); |
| 6903 | } catch (RemoteException e) { |
| 6904 | // ignore |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | @Override |
| 6909 | public void onError(int error) { |
| 6910 | try { |
| 6911 | callback.onError(error); |
| 6912 | } catch (RemoteException e) { |
| 6913 | // ignore |
| 6914 | } |
| 6915 | } |
| 6916 | }); |
| 6917 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6918 | } finally { |
| 6919 | Binder.restoreCallingIdentity(identity); |
| 6920 | } |
| 6921 | } |
| 6922 | |
| 6923 | /** |
| 6924 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6925 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6926 | */ |
| 6927 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6928 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6929 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6930 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6931 | |
| 6932 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6933 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6934 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6935 | long identity = Binder.clearCallingIdentity(); |
| 6936 | try { |
| 6937 | if (DBG) { |
| 6938 | log("setCallForwarding: subId " + subId |
| 6939 | + " callForwardingInfo" + callForwardingInfo); |
| 6940 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6941 | |
| 6942 | Phone phone = getPhone(subId); |
| 6943 | if (phone == null) { |
| 6944 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6945 | callback.accept( |
| 6946 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6947 | } catch (RemoteException e) { |
| 6948 | // ignore |
| 6949 | } |
| 6950 | return; |
| 6951 | } |
| 6952 | |
| 6953 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6954 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6955 | |
| 6956 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6957 | } finally { |
| 6958 | Binder.restoreCallingIdentity(identity); |
| 6959 | } |
| 6960 | } |
| 6961 | |
| 6962 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6963 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6964 | */ |
| 6965 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6966 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6967 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6968 | |
| 6969 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6970 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 6971 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6972 | long identity = Binder.clearCallingIdentity(); |
| 6973 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6974 | Phone phone = getPhone(subId); |
| 6975 | if (phone == null) { |
| 6976 | try { |
| 6977 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6978 | } catch (RemoteException e) { |
| 6979 | // ignore |
| 6980 | } |
| 6981 | return; |
| 6982 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6983 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6984 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6985 | boolean requireUssd = c.getBoolean( |
| 6986 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6987 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6988 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6989 | if (requireUssd) { |
| 6990 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6991 | getSubscriptionCarrierId(subId)); |
| 6992 | String newUssdCommand = ""; |
| 6993 | try { |
| 6994 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6995 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6996 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6997 | } catch (NullPointerException e) { |
| 6998 | loge("Failed to generate USSD number" + e); |
| 6999 | } |
| 7000 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7001 | mMainThreadHandler, callback, carrierXmlParser, |
| 7002 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7003 | final String ussdCommand = newUssdCommand; |
| 7004 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7005 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7006 | }); |
| 7007 | } else { |
| 7008 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7009 | callback::accept); |
| 7010 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7011 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7012 | } finally { |
| 7013 | Binder.restoreCallingIdentity(identity); |
| 7014 | } |
| 7015 | } |
| 7016 | |
| 7017 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7018 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7019 | */ |
| 7020 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7021 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7022 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7023 | |
| 7024 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7025 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7026 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7027 | long identity = Binder.clearCallingIdentity(); |
| 7028 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7029 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7030 | |
| 7031 | Phone phone = getPhone(subId); |
| 7032 | if (phone == null) { |
| 7033 | try { |
| 7034 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7035 | } catch (RemoteException e) { |
| 7036 | // ignore |
| 7037 | } |
| 7038 | return; |
| 7039 | } |
| 7040 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7041 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7042 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7043 | boolean requireUssd = c.getBoolean( |
| 7044 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7045 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7046 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7047 | if (requireUssd) { |
| 7048 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7049 | getSubscriptionCarrierId(subId)); |
| 7050 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7051 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7052 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7053 | String newUssdCommand = ""; |
| 7054 | try { |
| 7055 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7056 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7057 | .makeCommand(ssAction, null); |
| 7058 | } catch (NullPointerException e) { |
| 7059 | loge("Failed to generate USSD number" + e); |
| 7060 | } |
| 7061 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7062 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7063 | final String ussdCommand = newUssdCommand; |
| 7064 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7065 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7066 | }); |
| 7067 | } else { |
| 7068 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7069 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7070 | |
| 7071 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7072 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7073 | } finally { |
| 7074 | Binder.restoreCallingIdentity(identity); |
| 7075 | } |
| 7076 | } |
| 7077 | |
| 7078 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7079 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7080 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7081 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7082 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7083 | * location related information which will be sent if the caller already possess |
| 7084 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7085 | * @param request contains the radio access networks with bands/channels to scan |
| 7086 | * @param messenger callback messenger for scan results or errors |
| 7087 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7088 | * @return the id of the requested scan which can be used to stop the scan. |
| 7089 | */ |
| 7090 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7091 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7092 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7093 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7095 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7096 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7097 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7098 | if (!renounceFineLocationAccess) { |
| 7099 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7100 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7101 | .setCallingPackage(callingPackage) |
| 7102 | .setCallingFeatureId(callingFeatureId) |
| 7103 | .setCallingPid(Binder.getCallingPid()) |
| 7104 | .setCallingUid(Binder.getCallingUid()) |
| 7105 | .setMethod("requestNetworkScan") |
| 7106 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7107 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7108 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7109 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7110 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7111 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7112 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7113 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7114 | if (e != null) { |
| 7115 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7116 | throw e; |
| 7117 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7118 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7119 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7120 | } |
| 7121 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7122 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7123 | |
| 7124 | enforceTelephonyFeatureWithException(callingPackage, |
| 7125 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7126 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7127 | int callingUid = Binder.getCallingUid(); |
| 7128 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7129 | final long identity = Binder.clearCallingIdentity(); |
| 7130 | try { |
| 7131 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7132 | renounceFineLocationAccess, request, messenger, binder, |
| 7133 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7134 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
| 7137 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7138 | } |
| 7139 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7140 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7141 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7142 | boolean hasCarrierPriv; |
| 7143 | final long identity = Binder.clearCallingIdentity(); |
| 7144 | try { |
| 7145 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7146 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7147 | } finally { |
| 7148 | Binder.restoreCallingIdentity(identity); |
| 7149 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7150 | boolean hasNetworkScanPermission = |
| 7151 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7152 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7153 | |
| 7154 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7155 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7156 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7157 | } |
| 7158 | |
| 7159 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7160 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7161 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7162 | return new SecurityException("Specific channels must not be" |
| 7163 | + " scanned without location access."); |
| 7164 | } |
| 7165 | } |
| 7166 | } |
| 7167 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7168 | return null; |
| 7169 | } |
| 7170 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7171 | /** |
| 7172 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7173 | * |
| 7174 | * @param subId id of the subscription |
| 7175 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7176 | */ |
| 7177 | @Override |
| 7178 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7179 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7180 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7182 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7183 | final long identity = Binder.clearCallingIdentity(); |
| 7184 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7185 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7186 | } finally { |
| 7187 | Binder.restoreCallingIdentity(identity); |
| 7188 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
| 7191 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7192 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7193 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7194 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7195 | */ |
| 7196 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7197 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7198 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7199 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7200 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7201 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7202 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7203 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7205 | final long identity = Binder.clearCallingIdentity(); |
| 7206 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7207 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7208 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7209 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7210 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7211 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7212 | } finally { |
| 7213 | Binder.restoreCallingIdentity(identity); |
| 7214 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7215 | } |
| 7216 | |
| 7217 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7218 | * Get the allowed network types for certain reason. |
| 7219 | * |
| 7220 | * @param subId the id of the subscription. |
| 7221 | * @param reason the reason the allowed network type change is taking place |
| 7222 | * @return the allowed network types. |
| 7223 | */ |
| 7224 | @Override |
| 7225 | public long getAllowedNetworkTypesForReason(int subId, |
| 7226 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7227 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7228 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7229 | |
| 7230 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7231 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7232 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7233 | final long identity = Binder.clearCallingIdentity(); |
| 7234 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7235 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7236 | } finally { |
| 7237 | Binder.restoreCallingIdentity(identity); |
| 7238 | } |
| 7239 | } |
| 7240 | |
| 7241 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7242 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7243 | * @param subId subscription id of the sim card |
| 7244 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7245 | * This can be passed following states |
| 7246 | * <ol> |
| 7247 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7248 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7249 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7250 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7251 | * </ol> |
| 7252 | * @return operation result. |
| 7253 | */ |
| 7254 | @Override |
| 7255 | public int setNrDualConnectivityState(int subId, |
| 7256 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7257 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7258 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7259 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7260 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7261 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7262 | } |
| 7263 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7264 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7265 | final long identity = Binder.clearCallingIdentity(); |
| 7266 | try { |
| 7267 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7268 | nrDualConnectivityState, subId, |
| 7269 | workSource); |
| 7270 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7271 | return result; |
| 7272 | } finally { |
| 7273 | Binder.restoreCallingIdentity(identity); |
| 7274 | } |
| 7275 | } |
| 7276 | |
| 7277 | /** |
| 7278 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7279 | * @return true if dual connectivity is enabled else false |
| 7280 | */ |
| 7281 | @Override |
| 7282 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7283 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7284 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7285 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7286 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7287 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7288 | return false; |
| 7289 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7290 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
| 7293 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7294 | null, subId, workSource); |
| 7295 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7296 | return isEnabled; |
| 7297 | } finally { |
| 7298 | Binder.restoreCallingIdentity(identity); |
| 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7303 | * Set the allowed network types of the device and |
| 7304 | * provide the reason triggering the allowed network change. |
| 7305 | * |
| 7306 | * @param subId the id of the subscription. |
| 7307 | * @param reason the reason the allowed network type change is taking place |
| 7308 | * @param allowedNetworkTypes the allowed network types. |
| 7309 | * @return true on success; false on any failure. |
| 7310 | */ |
| 7311 | @Override |
| 7312 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7313 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7314 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7315 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7316 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7317 | // If the caller only has carrier privileges, then they should not be able to override |
| 7318 | // any network types which were set for security reasons. |
| 7319 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7320 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7321 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7322 | throw new SecurityException( |
| 7323 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7324 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7325 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7326 | |
| 7327 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7328 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7329 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7330 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7331 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7332 | return false; |
| 7333 | } |
| 7334 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7335 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7336 | return false; |
| 7337 | } |
| 7338 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7339 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7340 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7341 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7342 | Phone phone = getPhone(subId); |
| 7343 | if (phone == null) { |
| 7344 | return false; |
| 7345 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7346 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7347 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7348 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7349 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7350 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7351 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7352 | final long identity = Binder.clearCallingIdentity(); |
| 7353 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7354 | Boolean success = (Boolean) sendRequest( |
| 7355 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7356 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7357 | |
| 7358 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7359 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7360 | } finally { |
| 7361 | Binder.restoreCallingIdentity(identity); |
| 7362 | } |
| 7363 | } |
| 7364 | |
| 7365 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7366 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7367 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7368 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7369 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7370 | * @hide |
| 7371 | */ |
| 7372 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7373 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7374 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7375 | |
| 7376 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7377 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7379 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7380 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7381 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7382 | if (phone != null) { |
| 7383 | return phone.hasMatchedTetherApnSetting(); |
| 7384 | } else { |
| 7385 | return false; |
| 7386 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7387 | } finally { |
| 7388 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7389 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7390 | } |
| 7391 | |
| 7392 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7393 | * Get the user enabled state of Mobile Data. |
| 7394 | * |
| 7395 | * TODO: remove and use isUserDataEnabled. |
| 7396 | * This can't be removed now because some vendor codes |
| 7397 | * calls through ITelephony directly while they should |
| 7398 | * use TelephonyManager. |
| 7399 | * |
| 7400 | * @return true on enabled |
| 7401 | */ |
| 7402 | @Override |
| 7403 | public boolean getDataEnabled(int subId) { |
| 7404 | return isUserDataEnabled(subId); |
| 7405 | } |
| 7406 | |
| 7407 | /** |
| 7408 | * Get whether mobile data is enabled per user setting. |
| 7409 | * |
| 7410 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7411 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7412 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7413 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7414 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7415 | * |
| 7416 | * @return {@code true} if data is enabled else {@code false} |
| 7417 | */ |
| 7418 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7419 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7420 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7421 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7422 | try { |
| 7423 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7424 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7425 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7426 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7427 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7428 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7429 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7430 | mApp, subId, functionName); |
| 7431 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7432 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7433 | |
| 7434 | final long identity = Binder.clearCallingIdentity(); |
| 7435 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7436 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7437 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7438 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7439 | if (phone != null) { |
| 7440 | boolean retVal = phone.isUserDataEnabled(); |
| 7441 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7442 | return retVal; |
| 7443 | } else { |
| 7444 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7445 | return false; |
| 7446 | } |
| 7447 | } finally { |
| 7448 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7449 | } |
| 7450 | } |
| 7451 | |
| 7452 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7453 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7454 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7455 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7456 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7457 | * @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] | 7458 | */ |
| 7459 | @Override |
| 7460 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7461 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7462 | try { |
| 7463 | try { |
| 7464 | mApp.enforceCallingOrSelfPermission( |
| 7465 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7466 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7467 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7468 | try { |
| 7469 | mApp.enforceCallingOrSelfPermission( |
| 7470 | android.Manifest.permission.READ_PHONE_STATE, |
| 7471 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7472 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7473 | mApp.enforceCallingOrSelfPermission( |
| 7474 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7475 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7476 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7477 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7478 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7479 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7480 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7481 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7482 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7483 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | final long identity = Binder.clearCallingIdentity(); |
| 7485 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7486 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7488 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7489 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7490 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7491 | return retVal; |
| 7492 | } else { |
| 7493 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7494 | return false; |
| 7495 | } |
| 7496 | } finally { |
| 7497 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7498 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7499 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7500 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7501 | /** |
| 7502 | * Check if data is enabled for a specific reason |
| 7503 | * @param subId Subscription index |
| 7504 | * @param reason the reason the data enable change is taking place |
| 7505 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7506 | */ |
| 7507 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7508 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7509 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7510 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7511 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7512 | try { |
| 7513 | mApp.enforceCallingOrSelfPermission( |
| 7514 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7515 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7516 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7517 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7518 | functionName); |
| 7519 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7520 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7521 | try { |
| 7522 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7523 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7524 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7525 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7526 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7527 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7528 | } |
| 7529 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7530 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7531 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7532 | |
| 7533 | final long identity = Binder.clearCallingIdentity(); |
| 7534 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7535 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7536 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7537 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7538 | + " reason=" + reason); |
| 7539 | } |
| 7540 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7541 | if (phone != null) { |
| 7542 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7543 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7544 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7545 | return retVal; |
| 7546 | } else { |
| 7547 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7548 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7549 | + subId + " retVal=false"); |
| 7550 | } |
| 7551 | return false; |
| 7552 | } |
| 7553 | } finally { |
| 7554 | Binder.restoreCallingIdentity(identity); |
| 7555 | } |
| 7556 | } |
| 7557 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7558 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7559 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7560 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7561 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7562 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7563 | // No permission needed; this only lets the caller inspect their own status. |
| 7564 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7565 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7566 | |
| 7567 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7568 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7569 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7570 | |
| 7571 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7572 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7573 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7574 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7575 | } |
| 7576 | |
| 7577 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7578 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7579 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7580 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7581 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7582 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7583 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7584 | if (cpt == null) { |
| 7585 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7586 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7587 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7588 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7592 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7593 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7594 | |
| 7595 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7596 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7597 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7598 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7599 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7600 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7601 | Phone phone = getPhone(subId); |
| 7602 | if (phone == null) { |
| 7603 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7604 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7605 | } |
| 7606 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7607 | if (cpt == null) { |
| 7608 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7609 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7610 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7611 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7612 | } |
| 7613 | |
| 7614 | @Override |
| 7615 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7616 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7617 | |
| 7618 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7619 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7620 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7621 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7622 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7623 | } |
| 7624 | |
| 7625 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7626 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7627 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7628 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7629 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7630 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7631 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7632 | if (phone == null) { |
| 7633 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7634 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7635 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7636 | if (cpt == null) { |
| 7637 | continue; |
| 7638 | } |
| 7639 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7640 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7641 | break; |
| 7642 | } |
| 7643 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7644 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7645 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7646 | |
| 7647 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7648 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7649 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7650 | |
| 7651 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7652 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7653 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7654 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7655 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7656 | if (phone == null) { |
| 7657 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7658 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7659 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7660 | if (cpt == null) { |
| 7661 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7662 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7663 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7664 | } |
| 7665 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7666 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7667 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7668 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7669 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7670 | if (phone == null) { |
| 7671 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7672 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7673 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7674 | if (cpt == null) { |
| 7675 | return Collections.emptyList(); |
| 7676 | } |
| 7677 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7678 | } |
| 7679 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7680 | @Override |
| 7681 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7682 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7683 | |
| 7684 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7685 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7686 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7687 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7688 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7689 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7690 | try { |
| 7691 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7692 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7693 | } |
| 7694 | } finally { |
| 7695 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7696 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7697 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7698 | } |
| 7699 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7700 | @Override |
| 7701 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7702 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7703 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7704 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7705 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7706 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7707 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7708 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7709 | if (phone == null) { |
| 7710 | return null; |
| 7711 | } |
| 7712 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7713 | if (cpt == null) { |
| 7714 | return null; |
| 7715 | } |
| 7716 | return cpt.getCarrierServicePackageName(); |
| 7717 | } |
| 7718 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7719 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7720 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7721 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7722 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7723 | return null; |
| 7724 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7725 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7726 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7727 | return null; |
| 7728 | } |
| 7729 | return iccId; |
| 7730 | } |
| 7731 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7732 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7733 | public void setCallComposerStatus(int subId, int status) { |
| 7734 | enforceModifyPermission(); |
| 7735 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7736 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7737 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7738 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7739 | final long identity = Binder.clearCallingIdentity(); |
| 7740 | try { |
| 7741 | Phone phone = getPhone(subId); |
| 7742 | if (phone != null) { |
| 7743 | Phone defaultPhone = phone.getImsPhone(); |
| 7744 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7745 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7746 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7747 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7748 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7749 | } |
| 7750 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7751 | } catch (ImsException e) { |
| 7752 | throw new ServiceSpecificException(e.getCode()); |
| 7753 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7754 | Binder.restoreCallingIdentity(identity); |
| 7755 | } |
| 7756 | } |
| 7757 | |
| 7758 | @Override |
| 7759 | public int getCallComposerStatus(int subId) { |
| 7760 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7761 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7762 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7763 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7764 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7765 | final long identity = Binder.clearCallingIdentity(); |
| 7766 | try { |
| 7767 | Phone phone = getPhone(subId); |
| 7768 | if (phone != null) { |
| 7769 | Phone defaultPhone = phone.getImsPhone(); |
| 7770 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7771 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7772 | return imsPhone.getCallComposerStatus(); |
| 7773 | } |
| 7774 | } |
| 7775 | } finally { |
| 7776 | Binder.restoreCallingIdentity(identity); |
| 7777 | } |
| 7778 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7779 | } |
| 7780 | |
| 7781 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7782 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7783 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7784 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7785 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7786 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7787 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7788 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7789 | "setLine1NumberForDisplayForSubscriber"); |
| 7790 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7791 | final long identity = Binder.clearCallingIdentity(); |
| 7792 | try { |
| 7793 | final String iccId = getIccId(subId); |
| 7794 | final Phone phone = getPhone(subId); |
| 7795 | if (phone == null) { |
| 7796 | return false; |
| 7797 | } |
| 7798 | final String subscriberId = phone.getSubscriberId(); |
| 7799 | |
| 7800 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7801 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7802 | + subscriberId + " to " + number); |
| 7803 | } |
| 7804 | |
| 7805 | if (TextUtils.isEmpty(iccId)) { |
| 7806 | return false; |
| 7807 | } |
| 7808 | |
| 7809 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7810 | |
| 7811 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7812 | if (alphaTag == null) { |
| 7813 | editor.remove(alphaTagPrefKey); |
| 7814 | } else { |
| 7815 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7816 | } |
| 7817 | |
| 7818 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7819 | // track all merged IMSIs based on line number |
| 7820 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7821 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7822 | if (number == null) { |
| 7823 | editor.remove(numberPrefKey); |
| 7824 | editor.remove(subscriberPrefKey); |
| 7825 | } else { |
| 7826 | editor.putString(numberPrefKey, number); |
| 7827 | editor.putString(subscriberPrefKey, subscriberId); |
| 7828 | } |
| 7829 | |
| 7830 | editor.commit(); |
| 7831 | return true; |
| 7832 | } finally { |
| 7833 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7834 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7835 | } |
| 7836 | |
| 7837 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7838 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7839 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7840 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7841 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7842 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7843 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7844 | return null; |
| 7845 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7846 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7847 | enforceTelephonyFeatureWithException(callingPackage, |
| 7848 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7849 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7850 | final long identity = Binder.clearCallingIdentity(); |
| 7851 | try { |
| 7852 | String iccId = getIccId(subId); |
| 7853 | if (iccId != null) { |
| 7854 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7855 | if (DBG_MERGE) { |
| 7856 | log("getLine1NumberForDisplay returning " |
| 7857 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7858 | } |
| 7859 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7860 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7861 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7862 | return null; |
| 7863 | } finally { |
| 7864 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7865 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7866 | } |
| 7867 | |
| 7868 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7869 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7870 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7871 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7872 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7873 | return null; |
| 7874 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7875 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7876 | final long identity = Binder.clearCallingIdentity(); |
| 7877 | try { |
| 7878 | String iccId = getIccId(subId); |
| 7879 | if (iccId != null) { |
| 7880 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7881 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7882 | } |
| 7883 | return null; |
| 7884 | } finally { |
| 7885 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7886 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7887 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7888 | |
| 7889 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7890 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7891 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7892 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7893 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7894 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7895 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7896 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7897 | return null; |
| 7898 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7899 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7900 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7901 | // the process, where TelephonyManager was instantiated. |
| 7902 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7903 | final long identity = Binder.clearCallingIdentity(); |
| 7904 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7905 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7906 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7907 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7908 | |
| 7909 | // Figure out what subscribers are currently active |
| 7910 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7911 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7912 | // Only consider subs which match the current subId |
| 7913 | // This logic can be simplified. See b/131189269 for progress. |
| 7914 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7915 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7916 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7917 | |
| 7918 | // First pass, find a number override for an active subscriber |
| 7919 | String mergeNumber = null; |
| 7920 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7921 | for (String key : prefs.keySet()) { |
| 7922 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7923 | final String subscriberId = (String) prefs.get(key); |
| 7924 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7925 | final String iccId = key.substring( |
| 7926 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7927 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7928 | mergeNumber = (String) prefs.get(numberKey); |
| 7929 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7930 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7931 | + " for active subscriber " + subscriberId); |
| 7932 | } |
| 7933 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7934 | break; |
| 7935 | } |
| 7936 | } |
| 7937 | } |
| 7938 | } |
| 7939 | |
| 7940 | // Shortcut when no active merged subscribers |
| 7941 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7942 | return null; |
| 7943 | } |
| 7944 | |
| 7945 | // Second pass, find all subscribers under that line override |
| 7946 | final ArraySet<String> result = new ArraySet<>(); |
| 7947 | for (String key : prefs.keySet()) { |
| 7948 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7949 | final String number = (String) prefs.get(key); |
| 7950 | if (mergeNumber.equals(number)) { |
| 7951 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7952 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7953 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7954 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7955 | result.add(subscriberId); |
| 7956 | } |
| 7957 | } |
| 7958 | } |
| 7959 | } |
| 7960 | |
| 7961 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7962 | Arrays.sort(resultArray); |
| 7963 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7964 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7965 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7966 | } |
| 7967 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7968 | } finally { |
| 7969 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7970 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7971 | } |
| 7972 | |
| 7973 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7974 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7975 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7976 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7977 | enforceTelephonyFeatureWithException(callingPackage, |
| 7978 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 7979 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7980 | final long identity = Binder.clearCallingIdentity(); |
| 7981 | try { |
| 7982 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7983 | TelephonyManager.class); |
| 7984 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7985 | if (subscriberId == null) { |
| 7986 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7987 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7988 | + subId); |
| 7989 | } |
| 7990 | return null; |
| 7991 | } |
| 7992 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7993 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7994 | .getSubscriptionInfo(subId); |
| 7995 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7996 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7997 | if (groupUuid == null) { |
| 7998 | return new String[]{subscriberId}; |
| 7999 | } |
| 8000 | |
| 8001 | // Get all subscriberIds from the group. |
| 8002 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8003 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8004 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8005 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8006 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8007 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8008 | if (subscriberId != null) { |
| 8009 | mergedSubscriberIds.add(subscriberId); |
| 8010 | } |
| 8011 | } |
| 8012 | |
| 8013 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8014 | } finally { |
| 8015 | Binder.restoreCallingIdentity(identity); |
| 8016 | |
| 8017 | } |
| 8018 | } |
| 8019 | |
| 8020 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8021 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8022 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8023 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8024 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8025 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8026 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8027 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8028 | final long identity = Binder.clearCallingIdentity(); |
| 8029 | try { |
| 8030 | final Phone phone = getPhone(subId); |
| 8031 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8032 | } finally { |
| 8033 | Binder.restoreCallingIdentity(identity); |
| 8034 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8035 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8036 | |
| 8037 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8038 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8039 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8040 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8041 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8042 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8043 | |
| 8044 | final long identity = Binder.clearCallingIdentity(); |
| 8045 | try { |
| 8046 | final Phone phone = getPhone(subId); |
| 8047 | if (phone == null) { |
| 8048 | return false; |
| 8049 | } |
| 8050 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8051 | cdmaNonRoamingList); |
| 8052 | } finally { |
| 8053 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8054 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8055 | } |
| 8056 | |
| 8057 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8058 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8059 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8060 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8061 | if (phone == null) { |
| 8062 | return raf; |
| 8063 | } |
| 8064 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8065 | try { |
| 8066 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8067 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8068 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8069 | } catch (SecurityException e) { |
| 8070 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8071 | throw e; |
| 8072 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8073 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8074 | enforceTelephonyFeatureWithException(callingPackage, |
| 8075 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8076 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8077 | final long identity = Binder.clearCallingIdentity(); |
| 8078 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8079 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8080 | } finally { |
| 8081 | Binder.restoreCallingIdentity(identity); |
| 8082 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8083 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8084 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8085 | |
| 8086 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8087 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8088 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8089 | try { |
| 8090 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8091 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8092 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8093 | } |
| 8094 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8095 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8096 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8097 | |
| 8098 | enforceTelephonyFeatureWithException(callingPackage, |
| 8099 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8100 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8101 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8102 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8103 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8104 | throw new SecurityException("App must be the dialer role holder to" |
| 8105 | + " upload a call composer pic"); |
| 8106 | } |
| 8107 | |
| 8108 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8109 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8110 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8111 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8112 | boolean readUntilEnd = false; |
| 8113 | int totalBytesRead = 0; |
| 8114 | byte[] buffer = new byte[16 * 1024]; |
| 8115 | while (true) { |
| 8116 | int numRead; |
| 8117 | try { |
| 8118 | numRead = input.read(buffer); |
| 8119 | } catch (IOException e) { |
| 8120 | try { |
| 8121 | fd.checkError(); |
| 8122 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8123 | null); |
| 8124 | } catch (IOException e1) { |
| 8125 | // This means that the other side closed explicitly with an error. If this |
| 8126 | // happens, log and ignore. |
| 8127 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8128 | } |
| 8129 | break; |
| 8130 | } |
| 8131 | if (numRead == -1) { |
| 8132 | readUntilEnd = true; |
| 8133 | break; |
| 8134 | } |
| 8135 | totalBytesRead += numRead; |
| 8136 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8137 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8138 | try { |
| 8139 | input.close(); |
| 8140 | } catch (IOException e) { |
| 8141 | // ignore |
| 8142 | } |
| 8143 | break; |
| 8144 | } |
| 8145 | output.write(buffer, 0, numRead); |
| 8146 | } |
| 8147 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8148 | // close is above, where the picture size is too big. |
| 8149 | |
| 8150 | try { |
| 8151 | fd.checkError(); |
| 8152 | } catch (IOException e) { |
| 8153 | loge("Remote end for call composer closed with an error: " + e); |
| 8154 | return; |
| 8155 | } |
| 8156 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8157 | if (!readUntilEnd) { |
| 8158 | loge("Did not finish reading entire image; aborting"); |
| 8159 | return; |
| 8160 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8161 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8162 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8163 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8164 | new CallComposerPictureTransfer.Factory() {}, |
| 8165 | imageData, |
| 8166 | (result) -> { |
| 8167 | if (result.first != null) { |
| 8168 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8169 | Bundle outputResult = new Bundle(); |
| 8170 | outputResult.putParcelable( |
| 8171 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8172 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8173 | outputResult); |
| 8174 | } else { |
| 8175 | callback.send(result.second, null); |
| 8176 | } |
| 8177 | } |
| 8178 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8179 | }); |
| 8180 | } |
| 8181 | |
| 8182 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8183 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8184 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8185 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8186 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8187 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8188 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8190 | final long identity = Binder.clearCallingIdentity(); |
| 8191 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8192 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8193 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8194 | } finally { |
| 8195 | Binder.restoreCallingIdentity(identity); |
| 8196 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8197 | } |
| 8198 | |
| 8199 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8200 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8201 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8202 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8203 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8204 | return false; |
| 8205 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8206 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8207 | enforceTelephonyFeatureWithException(callingPackage, |
| 8208 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8210 | final long identity = Binder.clearCallingIdentity(); |
| 8211 | try { |
| 8212 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8213 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8214 | // In the long run, we may instead need to check if there exists a connection service |
| 8215 | // which can support video calling. |
| 8216 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8217 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8218 | return imsManager.isVtEnabledByPlatform() |
| 8219 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8220 | && imsManager.isVtEnabledByUser(); |
| 8221 | } finally { |
| 8222 | Binder.restoreCallingIdentity(identity); |
| 8223 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8224 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8225 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8226 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8227 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8228 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8229 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8230 | mApp, subId, callingPackage, callingFeatureId, |
| 8231 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8232 | return false; |
| 8233 | } |
| 8234 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8235 | enforceTelephonyFeatureWithException(callingPackage, |
| 8236 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8237 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8238 | final long identity = Binder.clearCallingIdentity(); |
| 8239 | try { |
| 8240 | CarrierConfigManager configManager = |
| 8241 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8242 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8243 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8244 | } finally { |
| 8245 | Binder.restoreCallingIdentity(identity); |
| 8246 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8247 | } |
| 8248 | |
| 8249 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8250 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8251 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8252 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8253 | return false; |
| 8254 | } |
| 8255 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8256 | enforceTelephonyFeatureWithException(callingPackage, |
| 8257 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8258 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8259 | final long identity = Binder.clearCallingIdentity(); |
| 8260 | try { |
| 8261 | CarrierConfigManager configManager = |
| 8262 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8263 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8264 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8265 | } finally { |
| 8266 | Binder.restoreCallingIdentity(identity); |
| 8267 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8268 | } |
| 8269 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8270 | @Override |
| 8271 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8272 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8273 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8274 | } |
| 8275 | |
| 8276 | @Override |
| 8277 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8278 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8279 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8280 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8281 | final long identity = Binder.clearCallingIdentity(); |
| 8282 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8283 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8284 | } finally { |
| 8285 | Binder.restoreCallingIdentity(identity); |
| 8286 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8287 | } |
| 8288 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8289 | /** |
| 8290 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8291 | * support for the feature and device firmware support. |
| 8292 | * |
| 8293 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8294 | */ |
| 8295 | @Override |
| 8296 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8297 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8298 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8300 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8301 | final Phone phone = getPhone(subscriptionId); |
| 8302 | if (phone == null) { |
| 8303 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8304 | return false; |
| 8305 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8306 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8307 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8308 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8309 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8310 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8311 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8312 | return isCarrierSupported && isDeviceSupported; |
| 8313 | } finally { |
| 8314 | Binder.restoreCallingIdentity(identity); |
| 8315 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8316 | } |
| 8317 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8318 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8319 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8320 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8321 | * 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] | 8322 | */ |
| 8323 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8324 | final long identity = Binder.clearCallingIdentity(); |
| 8325 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8326 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8327 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8328 | return false; |
| 8329 | } |
| 8330 | } |
| 8331 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8332 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8333 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8334 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8335 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8336 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8337 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 | } finally { |
| 8339 | Binder.restoreCallingIdentity(identity); |
| 8340 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8341 | } |
| 8342 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8343 | @Deprecated |
| 8344 | @Override |
| 8345 | public String getDeviceId(String callingPackage) { |
| 8346 | return getDeviceIdWithFeature(callingPackage, null); |
| 8347 | } |
| 8348 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8349 | /** |
| 8350 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8351 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8352 | * |
| 8353 | * <p>Requires Permission: |
| 8354 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8355 | */ |
| 8356 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8357 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8358 | try { |
| 8359 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8360 | } catch (SecurityException se) { |
| 8361 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8362 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8363 | + Binder.getCallingUid()); |
| 8364 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8365 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8366 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8367 | return null; |
| 8368 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8369 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8370 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8371 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8372 | return null; |
| 8373 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8374 | |
| 8375 | final long identity = Binder.clearCallingIdentity(); |
| 8376 | try { |
| 8377 | return phone.getDeviceId(); |
| 8378 | } finally { |
| 8379 | Binder.restoreCallingIdentity(identity); |
| 8380 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8381 | } |
| 8382 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8383 | /** |
| 8384 | * {@hide} |
| 8385 | * Returns the IMS Registration Status on a particular subid |
| 8386 | * |
| 8387 | * @param subId |
| 8388 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8389 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8390 | Phone phone = getPhone(subId); |
| 8391 | if (phone != null) { |
| 8392 | return phone.isImsRegistered(); |
| 8393 | } else { |
| 8394 | return false; |
| 8395 | } |
| 8396 | } |
| 8397 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8398 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8399 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8400 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8401 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8402 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8403 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8404 | } |
| 8405 | final long identity = Binder.clearCallingIdentity(); |
| 8406 | try { |
| 8407 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8408 | } finally { |
| 8409 | Binder.restoreCallingIdentity(identity); |
| 8410 | } |
| 8411 | } |
| 8412 | |
| 8413 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8414 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8415 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8416 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8417 | mApp, |
| 8418 | subscriptionId, |
| 8419 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8420 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8421 | |
| 8422 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8423 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8424 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8425 | final long identity = Binder.clearCallingIdentity(); |
| 8426 | try { |
| 8427 | Phone phone = getPhone(subscriptionId); |
| 8428 | if (phone == null) { |
| 8429 | return null; |
| 8430 | } |
| 8431 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8432 | } finally { |
| 8433 | Binder.restoreCallingIdentity(identity); |
| 8434 | } |
| 8435 | } |
| 8436 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8437 | /** |
| 8438 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8439 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8440 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8441 | final long identity = Binder.clearCallingIdentity(); |
| 8442 | try { |
| 8443 | Phone phone = getPhone(subId); |
| 8444 | if (phone != null) { |
| 8445 | return phone.isWifiCallingEnabled(); |
| 8446 | } else { |
| 8447 | return false; |
| 8448 | } |
| 8449 | } finally { |
| 8450 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8451 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8452 | } |
| 8453 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8454 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8455 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8456 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8457 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8458 | final long identity = Binder.clearCallingIdentity(); |
| 8459 | try { |
| 8460 | Phone phone = getPhone(subId); |
| 8461 | if (phone != null) { |
| 8462 | return phone.isVideoEnabled(); |
| 8463 | } else { |
| 8464 | return false; |
| 8465 | } |
| 8466 | } finally { |
| 8467 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8468 | } |
| 8469 | } |
| 8470 | |
| 8471 | /** |
| 8472 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8473 | * defined in {@link ImsRegistrationImplBase}. |
| 8474 | */ |
| 8475 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8476 | final long identity = Binder.clearCallingIdentity(); |
| 8477 | try { |
| 8478 | Phone phone = getPhone(subId); |
| 8479 | if (phone != null) { |
| 8480 | return phone.getImsRegistrationTech(); |
| 8481 | } else { |
| 8482 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8483 | } |
| 8484 | } finally { |
| 8485 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8486 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8487 | } |
| 8488 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8489 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8490 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8491 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8492 | |
| 8493 | enforceTelephonyFeatureWithException(callingPackage, |
| 8494 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8495 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8496 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8497 | return; |
| 8498 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8499 | Phone defaultPhone = getDefaultPhone(); |
| 8500 | if (defaultPhone != null) { |
| 8501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8502 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8503 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8504 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8505 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8506 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8507 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8508 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8509 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8510 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8511 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8512 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8513 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8514 | setDataRoamingEnabled(subId, phone == null ? false |
| 8515 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8516 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8517 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8518 | // There has been issues when Sms raw table somehow stores orphan |
| 8519 | // fragments. They lead to garbled message when new fragments come |
| 8520 | // in and combined with those stale ones. In case this happens again, |
| 8521 | // user can reset all network settings which will clean up this table. |
| 8522 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8523 | // Clean up IMS settings as well here. |
| 8524 | int slotId = getSlotIndex(subId); |
| 8525 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8526 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8527 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8528 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8529 | if (defaultPhone == null) { |
| 8530 | return; |
| 8531 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8532 | // Erase modem config if erase modem on network setting is enabled. |
| 8533 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8534 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8535 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8536 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8537 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8538 | |
| 8539 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8540 | } finally { |
| 8541 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8542 | } |
| 8543 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8544 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8545 | @VisibleForTesting |
| 8546 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8547 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8548 | return; |
| 8549 | } |
| 8550 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8551 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8552 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8553 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8554 | "user=" + defaultNetworkType); |
| 8555 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8556 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8557 | defaultNetworkType, null); |
| 8558 | } |
| 8559 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8560 | private void cleanUpSmsRawTable(Context context) { |
| 8561 | ContentResolver resolver = context.getContentResolver(); |
| 8562 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8563 | resolver.delete(uri, null, null); |
| 8564 | } |
| 8565 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8566 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8567 | public String getSimLocaleForSubscriber(int subId) { |
| 8568 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8569 | |
| 8570 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8571 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8572 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8573 | final Phone phone = getPhone(subId); |
| 8574 | if (phone == null) { |
| 8575 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8576 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8578 | final long identity = Binder.clearCallingIdentity(); |
| 8579 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8580 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8581 | phone.getContext().getOpPackageName(), |
| 8582 | phone.getContext().getAttributionTag()); |
| 8583 | if (info == null) { |
| 8584 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8585 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8586 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8587 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8588 | // preferences (EF-PL and EF-LI)... |
| 8589 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8590 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8591 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8592 | if (localeFromDefaultSim != null) { |
| 8593 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8594 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8595 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8596 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8597 | } else { |
| 8598 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8599 | } |
| 8600 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8602 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8603 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8604 | // the SIM and carrier preferences does not include a country we add the country |
| 8605 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8606 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8607 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8608 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8609 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8610 | } |
| 8611 | |
| 8612 | if (DBG) log("No locale found - returning null"); |
| 8613 | return null; |
| 8614 | } finally { |
| 8615 | Binder.restoreCallingIdentity(identity); |
| 8616 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8617 | } |
| 8618 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8619 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8620 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8621 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8622 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8623 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8624 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8625 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8626 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8627 | return localeTag; |
| 8628 | } |
| 8629 | } |
| 8630 | return inputLocale.toLanguageTag(); |
| 8631 | } |
| 8632 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8633 | /** |
| 8634 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8635 | */ |
| 8636 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8637 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8638 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8639 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8640 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8641 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8642 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8643 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8644 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8645 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8646 | * representing the state of the modem. |
| 8647 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8648 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8649 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8650 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8651 | */ |
| 8652 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8653 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8654 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8655 | |
| 8656 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8657 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8658 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8659 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8660 | |
| 8661 | final long identity = Binder.clearCallingIdentity(); |
| 8662 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8663 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8664 | } finally { |
| 8665 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8666 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8667 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8668 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8669 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8670 | // less than total activity duration. |
| 8671 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8672 | if (info == null) { |
| 8673 | return false; |
| 8674 | } |
| 8675 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8676 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8677 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8678 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8679 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8680 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8681 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8682 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8683 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8684 | } |
| 8685 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8686 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8687 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8688 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8689 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8690 | |
| 8691 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8692 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8693 | } |
| 8694 | |
| 8695 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8696 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8697 | rat, |
| 8698 | freq, |
| 8699 | info.getReceiveTimeMillis(rat, freq) |
| 8700 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8701 | } |
| 8702 | |
| 8703 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8704 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8705 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8706 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8707 | |
| 8708 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8709 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8710 | } |
| 8711 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8712 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8713 | rat, |
| 8714 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8715 | } |
| 8716 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8717 | /** |
| 8718 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8719 | * @param info recent ModemActivityInfo |
| 8720 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8721 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8722 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8723 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8724 | boolean matched; |
| 8725 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8726 | matched = false; |
| 8727 | int rat = info.getSpecificInfoRat(i); |
| 8728 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8729 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8730 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8731 | //if it already exists |
| 8732 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8733 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8734 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8735 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8736 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8737 | updateLastModemActivityInfo(info, rat, freq); |
| 8738 | matched = true; |
| 8739 | } |
| 8740 | } else { |
| 8741 | updateLastModemActivityInfo(info, rat); |
| 8742 | matched = true; |
| 8743 | } |
| 8744 | } |
| 8745 | } |
| 8746 | |
| 8747 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8748 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8749 | new ActivityStatsTechSpecificInfo( |
| 8750 | rat, |
| 8751 | freq, |
| 8752 | info.getTransmitTimeMillis(rat, freq), |
| 8753 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8754 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8755 | } |
| 8756 | } |
| 8757 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8758 | mLastModemActivitySpecificInfo = |
| 8759 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8760 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8761 | |
| 8762 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8763 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8764 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8765 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8766 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8767 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8768 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8769 | |
| 8770 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8771 | new ModemActivityInfo( |
| 8772 | mLastModemActivityInfo.getTimestampMillis(), |
| 8773 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8774 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8775 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8776 | } |
| 8777 | |
| 8778 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8779 | ActivityStatsTechSpecificInfo[] info) { |
| 8780 | int infoSize = info.length; |
| 8781 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8782 | for (int i = 0; i < infoSize; i++) { |
| 8783 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8784 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8785 | info[i].getTransmitTimeMillis(), |
| 8786 | (int) info[i].getReceiveTimeMillis()); |
| 8787 | } |
| 8788 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8789 | } |
| 8790 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8791 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8792 | * Returns the service state information on specified subscription. |
| 8793 | */ |
| 8794 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8795 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8796 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8797 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8798 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8799 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8800 | return null; |
| 8801 | } |
| 8802 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8803 | enforceTelephonyFeatureWithException(callingPackage, |
| 8804 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8805 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8806 | boolean hasFinePermission = false; |
| 8807 | boolean hasCoarsePermission = false; |
| 8808 | if (!renounceFineLocationAccess) { |
| 8809 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8810 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8811 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8812 | .setCallingPackage(callingPackage) |
| 8813 | .setCallingFeatureId(callingFeatureId) |
| 8814 | .setCallingPid(Binder.getCallingPid()) |
| 8815 | .setCallingUid(Binder.getCallingUid()) |
| 8816 | .setMethod("getServiceStateForSubscriber") |
| 8817 | .setLogAsInfo(true) |
| 8818 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8819 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8820 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8821 | .build()); |
| 8822 | hasFinePermission = |
| 8823 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8824 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8825 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8826 | if (!renounceCoarseLocationAccess) { |
| 8827 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8828 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8829 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8830 | .setCallingPackage(callingPackage) |
| 8831 | .setCallingFeatureId(callingFeatureId) |
| 8832 | .setCallingPid(Binder.getCallingPid()) |
| 8833 | .setCallingUid(Binder.getCallingUid()) |
| 8834 | .setMethod("getServiceStateForSubscriber") |
| 8835 | .setLogAsInfo(true) |
| 8836 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8837 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8838 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8839 | .build()); |
| 8840 | hasCoarsePermission = |
| 8841 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8842 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8843 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8844 | final Phone phone = getPhone(subId); |
| 8845 | if (phone == null) { |
| 8846 | return null; |
| 8847 | } |
| 8848 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8849 | final long identity = Binder.clearCallingIdentity(); |
| 8850 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8851 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8852 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8853 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8854 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8855 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8856 | .getSubscriptionInfoInternal(subId); |
| 8857 | if (subInfo == null || !subInfo.isActive()) { |
| 8858 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8859 | + "subId=" + subId); |
| 8860 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8861 | } |
| 8862 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8863 | ServiceState ss = phone.getServiceState(); |
| 8864 | |
| 8865 | // Scrub out the location info in ServiceState depending on what level of access |
| 8866 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8867 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8868 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8869 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8870 | } finally { |
| 8871 | Binder.restoreCallingIdentity(identity); |
| 8872 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8873 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8874 | |
| 8875 | /** |
| 8876 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8877 | * |
| 8878 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8879 | * voicemail ringtone. |
| 8880 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8881 | * PhoneAccount. |
| 8882 | */ |
| 8883 | @Override |
| 8884 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8885 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8886 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8888 | final long identity = Binder.clearCallingIdentity(); |
| 8889 | try { |
| 8890 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8891 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8892 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8893 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8894 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8895 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8896 | } finally { |
| 8897 | Binder.restoreCallingIdentity(identity); |
| 8898 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8899 | } |
| 8900 | |
| 8901 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8902 | * Sets the per-account voicemail ringtone. |
| 8903 | * |
| 8904 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8905 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8906 | * |
| 8907 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8908 | * voicemail ringtone. |
| 8909 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8910 | * PhoneAccount. |
| 8911 | */ |
| 8912 | @Override |
| 8913 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8914 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8915 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8916 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8917 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8918 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8920 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8921 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8922 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8923 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8924 | enforceTelephonyFeatureWithException(callingPackage, |
| 8925 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8926 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8927 | final long identity = Binder.clearCallingIdentity(); |
| 8928 | try { |
| 8929 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8930 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8931 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8932 | } |
| 8933 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8936 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8937 | } |
| 8938 | |
| 8939 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8940 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8941 | * |
| 8942 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8943 | * voicemail vibration setting. |
| 8944 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8945 | */ |
| 8946 | @Override |
| 8947 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8948 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8949 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8951 | final long identity = Binder.clearCallingIdentity(); |
| 8952 | try { |
| 8953 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8954 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8955 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8956 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8957 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8958 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8959 | } finally { |
| 8960 | Binder.restoreCallingIdentity(identity); |
| 8961 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8962 | } |
| 8963 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8964 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8965 | * Sets the per-account voicemail vibration. |
| 8966 | * |
| 8967 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8968 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8969 | * |
| 8970 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8971 | * voicemail vibration setting. |
| 8972 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8973 | * specific PhoneAccount. |
| 8974 | */ |
| 8975 | @Override |
| 8976 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8977 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8978 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8979 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8980 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8981 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8983 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8984 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8985 | } |
| 8986 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8987 | enforceTelephonyFeatureWithException(callingPackage, |
| 8988 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 8989 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8990 | final long identity = Binder.clearCallingIdentity(); |
| 8991 | try { |
| 8992 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8993 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8994 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8995 | } |
| 8996 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8997 | } finally { |
| 8998 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8999 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9000 | } |
| 9001 | |
| 9002 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9003 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9004 | * |
| 9005 | * @throws SecurityException if the caller does not have the required permission |
| 9006 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9007 | @VisibleForTesting |
| 9008 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9009 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9010 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9011 | } |
| 9012 | |
| 9013 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9014 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9015 | * permission. |
| 9016 | * |
| 9017 | * @throws SecurityException if the caller does not have the required permission |
| 9018 | */ |
| 9019 | private void enforceSendSmsPermission() { |
| 9020 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9021 | } |
| 9022 | |
| 9023 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9024 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9025 | * users permission. |
| 9026 | * |
| 9027 | * @throws SecurityException if the caller does not have the required permission |
| 9028 | */ |
| 9029 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9030 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9031 | } |
| 9032 | |
| 9033 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9034 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9035 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9036 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9037 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9038 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9039 | final long identity = Binder.clearCallingIdentity(); |
| 9040 | try { |
| 9041 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9042 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9043 | if (componentName == null) { |
| 9044 | throw new SecurityException( |
| 9045 | "Caller not current active visual voicemail package[null]"); |
| 9046 | } |
| 9047 | String vvmPackage = componentName.getPackageName(); |
| 9048 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9049 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9050 | } |
| 9051 | } finally { |
| 9052 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9053 | } |
| 9054 | } |
| 9055 | |
| 9056 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9057 | * Return the application ID for the app type. |
| 9058 | * |
| 9059 | * @param subId the subscription ID that this request applies to. |
| 9060 | * @param appType the uicc app type. |
| 9061 | * @return Application ID for specificied app type, or null if no uicc. |
| 9062 | */ |
| 9063 | @Override |
| 9064 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9065 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9066 | |
| 9067 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9068 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9069 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9070 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9071 | |
| 9072 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9073 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9074 | if (phone == null) { |
| 9075 | return null; |
| 9076 | } |
| 9077 | String aid = null; |
| 9078 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9079 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9080 | .getApplicationByType(appType).getAid(); |
| 9081 | } catch (Exception e) { |
| 9082 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9083 | } |
| 9084 | return aid; |
| 9085 | } finally { |
| 9086 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9087 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9088 | } |
| 9089 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9090 | /** |
| 9091 | * Return the Electronic Serial Number. |
| 9092 | * |
| 9093 | * @param subId the subscription ID that this request applies to. |
| 9094 | * @return ESN or null if error. |
| 9095 | */ |
| 9096 | @Override |
| 9097 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9098 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9099 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9100 | |
| 9101 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9102 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9103 | if (phone == null) { |
| 9104 | return null; |
| 9105 | } |
| 9106 | String esn = null; |
| 9107 | try { |
| 9108 | esn = phone.getEsn(); |
| 9109 | } catch (Exception e) { |
| 9110 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9111 | } |
| 9112 | return esn; |
| 9113 | } finally { |
| 9114 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9115 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9116 | } |
| 9117 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9118 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9119 | * Return the Preferred Roaming List Version. |
| 9120 | * |
| 9121 | * @param subId the subscription ID that this request applies to. |
| 9122 | * @return PRLVersion or null if error. |
| 9123 | */ |
| 9124 | @Override |
| 9125 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9126 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9127 | |
| 9128 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9129 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9130 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9131 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9132 | |
| 9133 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9134 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9135 | if (phone == null) { |
| 9136 | return null; |
| 9137 | } |
| 9138 | String cdmaPrlVersion = null; |
| 9139 | try { |
| 9140 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9141 | } catch (Exception e) { |
| 9142 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9143 | } |
| 9144 | return cdmaPrlVersion; |
| 9145 | } finally { |
| 9146 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9147 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9148 | } |
| 9149 | |
| 9150 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9151 | * Get snapshot of Telephony histograms |
| 9152 | * @return List of Telephony histograms |
| 9153 | * @hide |
| 9154 | */ |
| 9155 | @Override |
| 9156 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9158 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9159 | |
| 9160 | final long identity = Binder.clearCallingIdentity(); |
| 9161 | try { |
| 9162 | return RIL.getTelephonyRILTimingHistograms(); |
| 9163 | } finally { |
| 9164 | Binder.restoreCallingIdentity(identity); |
| 9165 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9166 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9167 | |
| 9168 | /** |
| 9169 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9170 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9171 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9172 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9173 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9174 | * @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] | 9175 | */ |
| 9176 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9177 | @TelephonyManager.SetCarrierRestrictionResult |
| 9178 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9179 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9180 | |
| 9181 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9182 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9183 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9184 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9185 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9186 | if (carrierRestrictionRules == null) { |
| 9187 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9188 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9190 | final long identity = Binder.clearCallingIdentity(); |
| 9191 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9192 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9193 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
| 9196 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9197 | } |
| 9198 | |
| 9199 | /** |
| 9200 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9201 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9202 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9203 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9204 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9205 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9206 | */ |
| 9207 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9208 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9209 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9210 | |
| 9211 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9212 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9213 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9214 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9215 | |
| 9216 | final long identity = Binder.clearCallingIdentity(); |
| 9217 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9218 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9219 | if (response instanceof CarrierRestrictionRules) { |
| 9220 | return (CarrierRestrictionRules) response; |
| 9221 | } |
| 9222 | // Response is an Exception of some kind, |
| 9223 | // which is signalled to the user as a NULL retval |
| 9224 | return null; |
| 9225 | } catch (Exception e) { |
| 9226 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9227 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9228 | } finally { |
| 9229 | Binder.restoreCallingIdentity(identity); |
| 9230 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9231 | } |
| 9232 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9233 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9234 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9235 | * through the callback. |
| 9236 | * |
| 9237 | * @param callback The callback that will be used to send the result. |
| 9238 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9239 | * the caller is not allowlisted. |
| 9240 | */ |
| 9241 | @Override |
| 9242 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9243 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9244 | |
| 9245 | enforceTelephonyFeatureWithException(packageName, |
| 9246 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9247 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9248 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9249 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9250 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9251 | throw new SecurityException("Not an authorized caller"); |
| 9252 | } |
| 9253 | final long identity = Binder.clearCallingIdentity(); |
| 9254 | try { |
| 9255 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9256 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9257 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9258 | } finally { |
| 9259 | Binder.restoreCallingIdentity(identity); |
| 9260 | } |
| 9261 | } |
| 9262 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9263 | @Override |
| 9264 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9265 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9266 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9267 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9268 | } |
| 9269 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9270 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9271 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9272 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9273 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9274 | } |
| 9275 | |
| 9276 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9277 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9278 | * @param subId the subscription ID that this action applies to. |
| 9279 | * @param enabled control enable or disable radio. |
| 9280 | * {@hide} |
| 9281 | */ |
| 9282 | @Override |
| 9283 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9284 | enforceModifyPermission(); |
| 9285 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9286 | |
| 9287 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9288 | if (phone == null) { |
| 9289 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9290 | return; |
| 9291 | } |
| 9292 | try { |
| 9293 | phone.carrierActionSetRadioEnabled(enabled); |
| 9294 | } catch (Exception e) { |
| 9295 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9296 | } finally { |
| 9297 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9298 | } |
| 9299 | } |
| 9300 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9301 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9302 | * Enable or disable Voice over NR (VoNR) |
| 9303 | * @param subId the subscription ID that this action applies to. |
| 9304 | * @param enabled enable or disable VoNR. |
| 9305 | * @return operation result. |
| 9306 | */ |
| 9307 | @Override |
| 9308 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9309 | enforceModifyPermission(); |
| 9310 | final Phone phone = getPhone(subId); |
| 9311 | |
| 9312 | final long identity = Binder.clearCallingIdentity(); |
| 9313 | if (phone == null) { |
| 9314 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9315 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9316 | } |
| 9317 | |
| 9318 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9319 | try { |
| 9320 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9321 | workSource); |
| 9322 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9323 | |
| 9324 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9325 | if (DBG) { |
| 9326 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9327 | } |
| 9328 | SubscriptionManager.setSubscriptionProperty( |
| 9329 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9330 | (enabled ? "1" : "0")); |
| 9331 | } |
| 9332 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9333 | return result; |
| 9334 | } finally { |
| 9335 | Binder.restoreCallingIdentity(identity); |
| 9336 | } |
| 9337 | } |
| 9338 | |
| 9339 | /** |
| 9340 | * Is voice over NR enabled |
| 9341 | * @return true if VoNR is enabled else false |
| 9342 | */ |
| 9343 | @Override |
| 9344 | public boolean isVoNrEnabled(int subId) { |
| 9345 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9346 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9347 | final long identity = Binder.clearCallingIdentity(); |
| 9348 | try { |
| 9349 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9350 | null, subId, workSource); |
| 9351 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9352 | return isEnabled; |
| 9353 | } finally { |
| 9354 | Binder.restoreCallingIdentity(identity); |
| 9355 | } |
| 9356 | } |
| 9357 | |
| 9358 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9359 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9360 | * network status based on which carrier apps could apply actions accordingly, |
| 9361 | * enable/disable default url handler for example. |
| 9362 | * |
| 9363 | * @param subId the subscription ID that this action applies to. |
| 9364 | * @param report control start/stop reporting the default network status. |
| 9365 | * {@hide} |
| 9366 | */ |
| 9367 | @Override |
| 9368 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9369 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9370 | |
| 9371 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9372 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9373 | "carrierActionReportDefaultNetworkStatus"); |
| 9374 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9375 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9376 | |
| 9377 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9378 | if (phone == null) { |
| 9379 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9380 | return; |
| 9381 | } |
| 9382 | try { |
| 9383 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9384 | } catch (Exception e) { |
| 9385 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9386 | } finally { |
| 9387 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9388 | } |
| 9389 | } |
| 9390 | |
| 9391 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9392 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9393 | * @param subId the subscription ID that this action applies to. |
| 9394 | * {@hide} |
| 9395 | */ |
| 9396 | @Override |
| 9397 | public void carrierActionResetAll(int subId) { |
| 9398 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9399 | |
| 9400 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9401 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9402 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9403 | final Phone phone = getPhone(subId); |
| 9404 | if (phone == null) { |
| 9405 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9406 | return; |
| 9407 | } |
| 9408 | try { |
| 9409 | phone.carrierActionResetAll(); |
| 9410 | } catch (Exception e) { |
| 9411 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9412 | } |
| 9413 | } |
| 9414 | |
| 9415 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9416 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9417 | * bug report is being generated. |
| 9418 | */ |
| 9419 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9420 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9421 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9422 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9423 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9424 | + Binder.getCallingPid() |
| 9425 | + ", uid=" + Binder.getCallingUid() |
| 9426 | + "without permission " |
| 9427 | + android.Manifest.permission.DUMP); |
| 9428 | return; |
| 9429 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9430 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9431 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9432 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9433 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9434 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9435 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9436 | @NonNull String[] args) { |
| 9437 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9438 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9439 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9440 | } |
| 9441 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9442 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9443 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9444 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9445 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9446 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9447 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9448 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9449 | */ |
| 9450 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9451 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9452 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9453 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9454 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9455 | try { |
| 9456 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9457 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9458 | } catch (SecurityException se) { |
| 9459 | enforceModifyPermission(); |
| 9460 | } |
| 9461 | } else { |
| 9462 | enforceModifyPermission(); |
| 9463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9464 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9465 | enforceTelephonyFeatureWithException(callingPackage, |
| 9466 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9467 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9468 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9469 | final long identity = Binder.clearCallingIdentity(); |
| 9470 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9471 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9472 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9473 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9474 | callingUid, callingPackage, null, null); |
| 9475 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9476 | Phone phone = getPhone(subId); |
| 9477 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9478 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9479 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9480 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9481 | phone.getDataSettingsManager().setDataEnabled( |
| 9482 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9483 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9484 | } |
| 9485 | } finally { |
| 9486 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9487 | } |
| 9488 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9489 | |
| 9490 | /** |
| 9491 | * Get Client request stats |
| 9492 | * @return List of Client Request Stats |
| 9493 | * @hide |
| 9494 | */ |
| 9495 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9496 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9497 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9498 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9499 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9500 | return null; |
| 9501 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9502 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9503 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9504 | final long identity = Binder.clearCallingIdentity(); |
| 9505 | try { |
| 9506 | if (phone != null) { |
| 9507 | return phone.getClientRequestStats(); |
| 9508 | } |
| 9509 | |
| 9510 | return null; |
| 9511 | } finally { |
| 9512 | Binder.restoreCallingIdentity(identity); |
| 9513 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9514 | } |
| 9515 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9516 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9517 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9518 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9519 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9520 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9521 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9522 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9523 | // commands that plumb through the RIL as root, like so: |
| 9524 | // $ adb root |
| 9525 | // $ adb shell cmd phone ... |
| 9526 | packageName = "root"; |
| 9527 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9528 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9529 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9530 | |
| 9531 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9532 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9533 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9534 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9535 | * @param state State of SIM (power down, power up, pass through) |
| 9536 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9537 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9538 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9539 | * |
| 9540 | **/ |
| 9541 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9542 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9543 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9544 | |
| 9545 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9546 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9547 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9548 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9549 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9550 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9551 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9552 | final long identity = Binder.clearCallingIdentity(); |
| 9553 | try { |
| 9554 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9555 | phone.setSimPowerState(state, null, workSource); |
| 9556 | } |
| 9557 | } finally { |
| 9558 | Binder.restoreCallingIdentity(identity); |
| 9559 | } |
| 9560 | } |
| 9561 | |
| 9562 | /** |
| 9563 | * Set SIM card power state. |
| 9564 | * |
| 9565 | * @param slotIndex SIM slot id. |
| 9566 | * @param state State of SIM (power down, power up, pass through) |
| 9567 | * @param callback callback to trigger after success or failure |
| 9568 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9569 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9570 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9571 | * |
| 9572 | **/ |
| 9573 | @Override |
| 9574 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9575 | IIntegerConsumer callback) { |
| 9576 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9577 | |
| 9578 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9579 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9580 | "setSimPowerStateForSlotWithCallback"); |
| 9581 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9582 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9583 | |
| 9584 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9585 | |
| 9586 | final long identity = Binder.clearCallingIdentity(); |
| 9587 | try { |
| 9588 | if (phone != null) { |
| 9589 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9590 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9591 | } |
| 9592 | } finally { |
| 9593 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9594 | } |
| 9595 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9596 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9597 | private boolean isUssdApiAllowed(int subId) { |
| 9598 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9599 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9600 | if (configManager == null) { |
| 9601 | return false; |
| 9602 | } |
| 9603 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9604 | if (pb == null) { |
| 9605 | return false; |
| 9606 | } |
| 9607 | return pb.getBoolean( |
| 9608 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9609 | } |
| 9610 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9611 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9612 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9613 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9614 | * @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] | 9615 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9616 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9617 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9618 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9619 | |
| 9620 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9621 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9623 | final long identity = Binder.clearCallingIdentity(); |
| 9624 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9625 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9626 | } finally { |
| 9627 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9628 | } |
| 9629 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9630 | |
| 9631 | /** |
| 9632 | * Get the current signal strength information for the given subscription. |
| 9633 | * Because this information is not updated when the device is in a low power state |
| 9634 | * it should not be relied-upon to be current. |
| 9635 | * @param subId Subscription index |
| 9636 | * @return the most recent cached signal strength info from the modem |
| 9637 | */ |
| 9638 | @Override |
| 9639 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9640 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9641 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9643 | final long identity = Binder.clearCallingIdentity(); |
| 9644 | try { |
| 9645 | Phone p = getPhone(subId); |
| 9646 | if (p == null) { |
| 9647 | return null; |
| 9648 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9650 | return p.getSignalStrength(); |
| 9651 | } finally { |
| 9652 | Binder.restoreCallingIdentity(identity); |
| 9653 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9654 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9655 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9656 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9657 | * Get the current modem radio state for the given slot. |
| 9658 | * @param slotIndex slot index. |
| 9659 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9660 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9661 | * @return the current radio power state from the modem |
| 9662 | */ |
| 9663 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9664 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9665 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9666 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9667 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9668 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9669 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9670 | } |
| 9671 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9672 | enforceTelephonyFeatureWithException(callingPackage, |
| 9673 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9674 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9675 | final long identity = Binder.clearCallingIdentity(); |
| 9676 | try { |
| 9677 | return phone.getRadioPowerState(); |
| 9678 | } finally { |
| 9679 | Binder.restoreCallingIdentity(identity); |
| 9680 | } |
| 9681 | } |
| 9682 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9683 | } |
| 9684 | |
| 9685 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9686 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9687 | * |
| 9688 | * <p>Requires one of the following permissions: |
| 9689 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9690 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9691 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9692 | * privileges. |
| 9693 | * |
| 9694 | * @param subId subscription id |
| 9695 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9696 | * {@code false}. |
| 9697 | */ |
| 9698 | @Override |
| 9699 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9700 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9701 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9702 | try { |
| 9703 | mApp.enforceCallingOrSelfPermission( |
| 9704 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9705 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9706 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9707 | mApp.enforceCallingOrSelfPermission( |
| 9708 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9709 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9710 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9711 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9712 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9713 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9714 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9715 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9716 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9717 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9718 | boolean isEnabled = false; |
| 9719 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9720 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9721 | Phone phone = getPhone(subId); |
| 9722 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9723 | } finally { |
| 9724 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9725 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9726 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9727 | } |
| 9728 | |
| 9729 | |
| 9730 | /** |
| 9731 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9732 | * |
| 9733 | * <p> Requires permission: |
| 9734 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9735 | * privileges. |
| 9736 | * |
| 9737 | * @param subId subscription id |
| 9738 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9739 | */ |
| 9740 | @Override |
| 9741 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9742 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9743 | mApp, subId, "setDataRoamingEnabled"); |
| 9744 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9745 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9746 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9747 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9748 | final long identity = Binder.clearCallingIdentity(); |
| 9749 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9750 | Phone phone = getPhone(subId); |
| 9751 | if (phone != null) { |
| 9752 | phone.setDataRoamingEnabled(isEnabled); |
| 9753 | } |
| 9754 | } finally { |
| 9755 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9756 | } |
| 9757 | } |
| 9758 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9759 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9760 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9761 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9762 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9763 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9764 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9765 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9766 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9767 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9768 | boolean isAllowed = true; |
| 9769 | final long identity = Binder.clearCallingIdentity(); |
| 9770 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9771 | Phone phone = getPhone(subId); |
| 9772 | if (phone != null) { |
| 9773 | isAllowed = phone.isCspPlmnEnabled(); |
| 9774 | } |
| 9775 | } finally { |
| 9776 | Binder.restoreCallingIdentity(identity); |
| 9777 | } |
| 9778 | return isAllowed; |
| 9779 | } |
| 9780 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9781 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9782 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9783 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9784 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9785 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9786 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9787 | if (phone == null) { |
| 9788 | return false; |
| 9789 | } |
| 9790 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9791 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9792 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9793 | } |
| 9794 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9795 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9796 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9797 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9798 | mApp.getSystemService(AppOpsManager.class) |
| 9799 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9800 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9801 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9802 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9803 | try { |
| 9804 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9805 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9806 | } catch (SecurityException e) { |
| 9807 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9808 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9809 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9810 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9811 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9812 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9813 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9814 | |
| 9815 | enforceTelephonyFeatureWithException(callingPackage, |
| 9816 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9817 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9818 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9819 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9820 | Binder.getCallingUid())) { |
| 9821 | isIccIdAccessRestricted = true; |
| 9822 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9823 | final long identity = Binder.clearCallingIdentity(); |
| 9824 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9825 | UiccController uiccController = UiccController.getInstance(); |
| 9826 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9827 | if (hasReadPermission) { |
| 9828 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9829 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9830 | |
| 9831 | // Remove private info if the caller doesn't have access |
| 9832 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9833 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9834 | //setting the value after compatibility check |
| 9835 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9836 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9837 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9838 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9839 | if (card == null) { |
| 9840 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9841 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9842 | continue; |
| 9843 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9844 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9845 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9846 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9847 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9848 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9849 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9850 | for (UiccPortInfo portInfo : portInfos) { |
| 9851 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9852 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9853 | if (port == null) { |
| 9854 | // assume no access if port is null |
| 9855 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9856 | continue; |
| 9857 | } |
| 9858 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9859 | uiccPortInfos.add(portInfo); |
| 9860 | } else { |
| 9861 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9862 | } |
| 9863 | } |
| 9864 | filteredInfos.add(new UiccCardInfo( |
| 9865 | cardInfo.isEuicc(), |
| 9866 | cardInfo.getCardId(), |
| 9867 | null, |
| 9868 | cardInfo.getPhysicalSlotIndex(), |
| 9869 | cardInfo.isRemovable(), |
| 9870 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9871 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9872 | } |
| 9873 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9874 | } finally { |
| 9875 | Binder.restoreCallingIdentity(identity); |
| 9876 | } |
| 9877 | } |
| 9878 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9879 | /** |
| 9880 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9881 | * generally private and require carrier privileges to view. |
| 9882 | * |
| 9883 | * @hide |
| 9884 | */ |
| 9885 | @NonNull |
| 9886 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9887 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9888 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9889 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9890 | } |
| 9891 | return new UiccCardInfo( |
| 9892 | cardInfo.isEuicc(), |
| 9893 | cardInfo.getCardId(), |
| 9894 | null, |
| 9895 | cardInfo.getPhysicalSlotIndex(), |
| 9896 | cardInfo.isRemovable(), |
| 9897 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9898 | portinfo |
| 9899 | ); |
| 9900 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9901 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9902 | /** |
| 9903 | * @hide |
| 9904 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9905 | * These values are generally private and require carrier privileges to view. |
| 9906 | */ |
| 9907 | @NonNull |
| 9908 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9909 | return new UiccPortInfo( |
| 9910 | UiccPortInfo.ICCID_REDACTED, |
| 9911 | portInfo.getPortIndex(), |
| 9912 | portInfo.getLogicalSlotIndex(), |
| 9913 | portInfo.isActive() |
| 9914 | ); |
| 9915 | } |
| 9916 | @Override |
| 9917 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9918 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9919 | mApp.getSystemService(AppOpsManager.class) |
| 9920 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9921 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9922 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9923 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9924 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9925 | // we are reading iccId which is PII data. |
| 9926 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9927 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9928 | enforceTelephonyFeatureWithException(callingPackage, |
| 9929 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9930 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9931 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9932 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9933 | Binder.getCallingUid())) { |
| 9934 | isLogicalSlotAccessRestricted = true; |
| 9935 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9936 | final long identity = Binder.clearCallingIdentity(); |
| 9937 | try { |
| 9938 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9939 | if (slots == null || slots.length == 0) { |
| 9940 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9941 | return null; |
| 9942 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9943 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9944 | for (int i = 0; i < slots.length; i++) { |
| 9945 | UiccSlot slot = slots[i]; |
| 9946 | if (slot == null) { |
| 9947 | continue; |
| 9948 | } |
| 9949 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9950 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9951 | UiccCard card = slot.getUiccCard(); |
| 9952 | if (card != null) { |
| 9953 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9954 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9955 | cardId = slot.getEid(); |
| 9956 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9957 | // If cardId is null, use iccId of default port as cardId. |
| 9958 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9959 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9960 | } |
| 9961 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9962 | if (cardId != null) { |
| 9963 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9964 | // if cardId is an EID, it's all digits so this is fine |
| 9965 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9966 | } |
| 9967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9968 | int cardState = 0; |
| 9969 | switch (slot.getCardState()) { |
| 9970 | case CARDSTATE_ABSENT: |
| 9971 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9972 | break; |
| 9973 | case CARDSTATE_PRESENT: |
| 9974 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9975 | break; |
| 9976 | case CARDSTATE_ERROR: |
| 9977 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9978 | break; |
| 9979 | case CARDSTATE_RESTRICTED: |
| 9980 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9981 | break; |
| 9982 | default: |
| 9983 | break; |
| 9984 | |
| 9985 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9986 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9987 | int[] portIndexes = slot.getPortList(); |
| 9988 | for (int portIdx : portIndexes) { |
| 9989 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9990 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9991 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9992 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9993 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9994 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9995 | slot.isEuicc(), |
| 9996 | cardId, |
| 9997 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9998 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9999 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10000 | //setting the value after compatibility check |
| 10001 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10002 | } |
| 10003 | return infos; |
| 10004 | } finally { |
| 10005 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10006 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10007 | } |
| 10008 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10009 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10010 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10011 | boolean hasReadPermission) { |
| 10012 | String iccId = slot.getIccId(portIndex); |
| 10013 | if (hasReadPermission) { // if has read permission |
| 10014 | return iccId; |
| 10015 | } else { |
| 10016 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10017 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10018 | // if no read permission, checking carrier privilege access |
| 10019 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10020 | return iccId; |
| 10021 | } |
| 10022 | } |
| 10023 | } |
| 10024 | // No read permission or carrier privilege access. |
| 10025 | return UiccPortInfo.ICCID_REDACTED; |
| 10026 | } |
| 10027 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10028 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10029 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10030 | public boolean switchSlots(int[] physicalSlots) { |
| 10031 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10032 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10033 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10034 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10035 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10036 | final long identity = Binder.clearCallingIdentity(); |
| 10037 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10038 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10039 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10040 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10041 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10042 | physicalSlots[i], i)); |
| 10043 | } |
| 10044 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10045 | } finally { |
| 10046 | Binder.restoreCallingIdentity(identity); |
| 10047 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10048 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10049 | |
| 10050 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10051 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10052 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10053 | enforceModifyPermission(); |
| 10054 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10055 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10056 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10057 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10058 | final long identity = Binder.clearCallingIdentity(); |
| 10059 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10060 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10061 | } finally { |
| 10062 | Binder.restoreCallingIdentity(identity); |
| 10063 | } |
| 10064 | } |
| 10065 | |
| 10066 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10067 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10068 | enforceTelephonyFeatureWithException(callingPackage, |
| 10069 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10070 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10071 | final long identity = Binder.clearCallingIdentity(); |
| 10072 | try { |
| 10073 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10074 | } finally { |
| 10075 | Binder.restoreCallingIdentity(identity); |
| 10076 | } |
| 10077 | } |
| 10078 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10079 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10080 | * A test API to reload the UICC profile. |
| 10081 | * |
| 10082 | * <p>Requires that the calling app has permission |
| 10083 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10084 | * @hide |
| 10085 | */ |
| 10086 | @Override |
| 10087 | public void refreshUiccProfile(int subId) { |
| 10088 | enforceModifyPermission(); |
| 10089 | |
| 10090 | final long identity = Binder.clearCallingIdentity(); |
| 10091 | try { |
| 10092 | Phone phone = getPhone(subId); |
| 10093 | if (phone == null) { |
| 10094 | return; |
| 10095 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10096 | UiccPort uiccPort = phone.getUiccPort(); |
| 10097 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10098 | return; |
| 10099 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10100 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10101 | if (uiccProfile == null) { |
| 10102 | return; |
| 10103 | } |
| 10104 | uiccProfile.refresh(); |
| 10105 | } finally { |
| 10106 | Binder.restoreCallingIdentity(identity); |
| 10107 | } |
| 10108 | } |
| 10109 | |
| 10110 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10111 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10112 | */ |
| 10113 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10114 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10115 | } |
| 10116 | |
| 10117 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10118 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10119 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10120 | */ |
| 10121 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10122 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10123 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10124 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10125 | return list.get(phoneId); |
| 10126 | } |
| 10127 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10128 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10129 | |
| 10130 | @Override |
| 10131 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10132 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10133 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10134 | |
| 10135 | final long identity = Binder.clearCallingIdentity(); |
| 10136 | try { |
| 10137 | final Phone phone = getPhone(subId); |
| 10138 | if (phone == null) { |
| 10139 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10140 | return; |
| 10141 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10142 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10143 | if (cpt != null) { |
| 10144 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10145 | } |
| 10146 | // 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] | 10147 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10148 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10149 | if (carrierPrivilegeRules == null) { |
| 10150 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10151 | } else { |
| 10152 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10153 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10154 | } finally { |
| 10155 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10156 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10157 | } |
| 10158 | |
| 10159 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10160 | public void setCarrierServicePackageOverride( |
| 10161 | int subId, String carrierServicePackage, String callingPackage) { |
| 10162 | TelephonyPermissions.enforceShellOnly( |
| 10163 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10164 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10165 | final long identity = Binder.clearCallingIdentity(); |
| 10166 | try { |
| 10167 | final Phone phone = getPhone(subId); |
| 10168 | if (phone == null || phone.getSubId() != subId) { |
| 10169 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10170 | throw new IllegalArgumentException("No phone for subid"); |
| 10171 | } |
| 10172 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10173 | if (cpt == null) { |
| 10174 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10175 | throw new IllegalStateException("No CPT for phone"); |
| 10176 | } |
| 10177 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10178 | } finally { |
| 10179 | Binder.restoreCallingIdentity(identity); |
| 10180 | } |
| 10181 | } |
| 10182 | |
| 10183 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10184 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10185 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10186 | |
| 10187 | final long identity = Binder.clearCallingIdentity(); |
| 10188 | try { |
| 10189 | final Phone phone = getPhone(subId); |
| 10190 | if (phone == null) { |
| 10191 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10192 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10193 | } |
| 10194 | return phone.getCarrierIdListVersion(); |
| 10195 | } finally { |
| 10196 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10197 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10198 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10199 | |
| 10200 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10201 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10202 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10203 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10204 | mApp, subId, callingPackage, callingFeatureId, |
| 10205 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10206 | return -1; |
| 10207 | } |
| 10208 | |
| 10209 | final long identity = Binder.clearCallingIdentity(); |
| 10210 | try { |
| 10211 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10212 | } finally { |
| 10213 | Binder.restoreCallingIdentity(identity); |
| 10214 | } |
| 10215 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10216 | |
| 10217 | @Override |
| 10218 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10219 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10220 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10221 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10222 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10223 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10224 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10225 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10226 | final long identity = Binder.clearCallingIdentity(); |
| 10227 | try { |
| 10228 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10229 | } finally { |
| 10230 | Binder.restoreCallingIdentity(identity); |
| 10231 | } |
| 10232 | } |
| 10233 | |
| 10234 | @Override |
| 10235 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10236 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10237 | mApp, subId, "setCdmaRoamingMode"); |
| 10238 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10239 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10240 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10241 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10242 | final long identity = Binder.clearCallingIdentity(); |
| 10243 | try { |
| 10244 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10245 | } finally { |
| 10246 | Binder.restoreCallingIdentity(identity); |
| 10247 | } |
| 10248 | } |
| 10249 | |
| 10250 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10251 | public int getCdmaSubscriptionMode(int subId) { |
| 10252 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10253 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10254 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10255 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10256 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10257 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10258 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10259 | final long identity = Binder.clearCallingIdentity(); |
| 10260 | try { |
| 10261 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10262 | } finally { |
| 10263 | Binder.restoreCallingIdentity(identity); |
| 10264 | } |
| 10265 | } |
| 10266 | |
| 10267 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10268 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10270 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10271 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10272 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10273 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10274 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10275 | final long identity = Binder.clearCallingIdentity(); |
| 10276 | try { |
| 10277 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10278 | } finally { |
| 10279 | Binder.restoreCallingIdentity(identity); |
| 10280 | } |
| 10281 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10282 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10283 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10284 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10285 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10286 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10287 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10288 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10289 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10290 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10291 | |
| 10292 | enforceTelephonyFeatureWithException(callingPackage, |
| 10293 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10294 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10295 | final long identity = Binder.clearCallingIdentity(); |
| 10296 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10297 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10298 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10299 | if (phone.getEmergencyNumberTracker() != null |
| 10300 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10301 | emergencyNumberListInternal.put( |
| 10302 | phone.getSubId(), |
| 10303 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10304 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10305 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10306 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10307 | } finally { |
| 10308 | Binder.restoreCallingIdentity(identity); |
| 10309 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10310 | } |
| 10311 | |
| 10312 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10313 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10314 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10315 | if (!exactMatch) { |
| 10316 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10317 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10318 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10319 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10320 | |
| 10321 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10322 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10323 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10324 | final long identity = Binder.clearCallingIdentity(); |
| 10325 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10326 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10327 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10328 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10329 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10330 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10331 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10332 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10333 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10334 | } |
| 10335 | return false; |
| 10336 | } finally { |
| 10337 | Binder.restoreCallingIdentity(identity); |
| 10338 | } |
| 10339 | } |
| 10340 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10341 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10342 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10343 | */ |
| 10344 | @Override |
| 10345 | public void startEmergencyCallbackMode() { |
| 10346 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10347 | "startEmergencyCallbackMode"); |
| 10348 | enforceModifyPermission(); |
| 10349 | final long identity = Binder.clearCallingIdentity(); |
| 10350 | try { |
| 10351 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10352 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10353 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10354 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10355 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10356 | gsmCdmaPhone.obtainMessage( |
| 10357 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10358 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10359 | } |
| 10360 | } |
| 10361 | } finally { |
| 10362 | Binder.restoreCallingIdentity(identity); |
| 10363 | } |
| 10364 | } |
| 10365 | |
| 10366 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10367 | * Update emergency number list for test mode. |
| 10368 | */ |
| 10369 | @Override |
| 10370 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10371 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10372 | "updateEmergencyNumberListTestMode"); |
| 10373 | |
| 10374 | final long identity = Binder.clearCallingIdentity(); |
| 10375 | try { |
| 10376 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10377 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10378 | if (tracker != null) { |
| 10379 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10380 | } |
| 10381 | } |
| 10382 | } finally { |
| 10383 | Binder.restoreCallingIdentity(identity); |
| 10384 | } |
| 10385 | } |
| 10386 | |
| 10387 | /** |
| 10388 | * Get the full emergency number list for test mode. |
| 10389 | */ |
| 10390 | @Override |
| 10391 | public List<String> getEmergencyNumberListTestMode() { |
| 10392 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10393 | "getEmergencyNumberListTestMode"); |
| 10394 | |
| 10395 | final long identity = Binder.clearCallingIdentity(); |
| 10396 | try { |
| 10397 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10398 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10399 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10400 | if (tracker != null) { |
| 10401 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10402 | emergencyNumbers.add(num.getNumber()); |
| 10403 | } |
| 10404 | } |
| 10405 | } |
| 10406 | return new ArrayList<>(emergencyNumbers); |
| 10407 | } finally { |
| 10408 | Binder.restoreCallingIdentity(identity); |
| 10409 | } |
| 10410 | } |
| 10411 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10412 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10413 | public int getEmergencyNumberDbVersion(int subId) { |
| 10414 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10415 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10416 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10417 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10418 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10419 | final long identity = Binder.clearCallingIdentity(); |
| 10420 | try { |
| 10421 | final Phone phone = getPhone(subId); |
| 10422 | if (phone == null) { |
| 10423 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10424 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10425 | } |
| 10426 | return phone.getEmergencyNumberDbVersion(); |
| 10427 | } finally { |
| 10428 | Binder.restoreCallingIdentity(identity); |
| 10429 | } |
| 10430 | } |
| 10431 | |
| 10432 | @Override |
| 10433 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10434 | enforceModifyPermission(); |
| 10435 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10436 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10437 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10438 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10439 | final long identity = Binder.clearCallingIdentity(); |
| 10440 | try { |
| 10441 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10442 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10443 | if (tracker != null) { |
| 10444 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10445 | } |
| 10446 | } |
| 10447 | } finally { |
| 10448 | Binder.restoreCallingIdentity(identity); |
| 10449 | } |
| 10450 | } |
| 10451 | |
| 10452 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10453 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10454 | enforceActiveEmergencySessionPermission(); |
| 10455 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10456 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10457 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10458 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10459 | final long identity = Binder.clearCallingIdentity(); |
| 10460 | try { |
| 10461 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10462 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10463 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10464 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10465 | } |
| 10466 | } |
| 10467 | } finally { |
| 10468 | Binder.restoreCallingIdentity(identity); |
| 10469 | } |
| 10470 | } |
| 10471 | |
| 10472 | @Override |
| 10473 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10474 | enforceActiveEmergencySessionPermission(); |
| 10475 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10476 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10477 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10478 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -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.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10485 | } |
| 10486 | } |
| 10487 | } finally { |
| 10488 | Binder.restoreCallingIdentity(identity); |
| 10489 | } |
| 10490 | } |
| 10491 | |
| 10492 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10493 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10494 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10495 | Phone phone = getPhone(subId); |
| 10496 | if (phone == null) { |
| 10497 | return null; |
| 10498 | } |
| 10499 | final long identity = Binder.clearCallingIdentity(); |
| 10500 | try { |
| 10501 | UiccProfile profile = UiccController.getInstance() |
| 10502 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10503 | if (profile != null) { |
| 10504 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10505 | } |
| 10506 | } finally { |
| 10507 | Binder.restoreCallingIdentity(identity); |
| 10508 | } |
| 10509 | return null; |
| 10510 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10511 | |
| 10512 | /** |
| 10513 | * Enable or disable a modem stack. |
| 10514 | */ |
| 10515 | @Override |
| 10516 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10517 | enforceModifyPermission(); |
| 10518 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10519 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10520 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10521 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10522 | final long identity = Binder.clearCallingIdentity(); |
| 10523 | try { |
| 10524 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10525 | if (phone == null) { |
| 10526 | return false; |
| 10527 | } else { |
| 10528 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10529 | } |
| 10530 | } finally { |
| 10531 | Binder.restoreCallingIdentity(identity); |
| 10532 | } |
| 10533 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10534 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10535 | /** |
| 10536 | * Whether a modem stack is enabled or not. |
| 10537 | */ |
| 10538 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10539 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10540 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10541 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10542 | if (phone == null) return false; |
| 10543 | |
| 10544 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10545 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10546 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10547 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10548 | } |
| 10549 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10550 | enforceTelephonyFeatureWithException(callingPackage, |
| 10551 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10552 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10553 | final long identity = Binder.clearCallingIdentity(); |
| 10554 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10555 | try { |
| 10556 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10557 | } catch (NoSuchElementException ex) { |
| 10558 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10559 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10560 | } finally { |
| 10561 | Binder.restoreCallingIdentity(identity); |
| 10562 | } |
| 10563 | } |
| 10564 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10565 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10566 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10567 | enforceModifyPermission(); |
| 10568 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10569 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10570 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10571 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10572 | final long identity = Binder.clearCallingIdentity(); |
| 10573 | try { |
| 10574 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10575 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10576 | .commit(); |
| 10577 | } finally { |
| 10578 | Binder.restoreCallingIdentity(identity); |
| 10579 | } |
| 10580 | } |
| 10581 | |
| 10582 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10583 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10584 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10585 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10586 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10587 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10588 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10589 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10590 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10591 | enforceTelephonyFeatureWithException(callingPackage, |
| 10592 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10593 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10594 | final long identity = Binder.clearCallingIdentity(); |
| 10595 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10596 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10597 | } finally { |
| 10598 | Binder.restoreCallingIdentity(identity); |
| 10599 | } |
| 10600 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10601 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10602 | @TelephonyManager.IsMultiSimSupportedResult |
| 10603 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10604 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10605 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10606 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10607 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10608 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10609 | } |
| 10610 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10611 | // supported by the modem, indicate that it is restricted. |
| 10612 | PhoneCapability staticCapability = |
| 10613 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10614 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10615 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10616 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10617 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10618 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10619 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10620 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10621 | } |
| 10622 | // Check if support of multiple SIMs is restricted by carrier |
| 10623 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10624 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10625 | } |
| 10626 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10627 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10628 | } |
| 10629 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10630 | /** |
| 10631 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10632 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10633 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10634 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10635 | * @param numOfSims number of active sims we want to switch to |
| 10636 | */ |
| 10637 | @Override |
| 10638 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10639 | if (numOfSims == 1) { |
| 10640 | enforceModifyPermission(); |
| 10641 | } else { |
| 10642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10643 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10644 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10645 | |
| 10646 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10647 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10648 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10649 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10650 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10651 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10652 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10653 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10654 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10655 | return; |
| 10656 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10657 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10658 | } finally { |
| 10659 | Binder.restoreCallingIdentity(identity); |
| 10660 | } |
| 10661 | } |
| 10662 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10663 | @Override |
| 10664 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10665 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10666 | |
| 10667 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10668 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10669 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10670 | Phone phone = getPhone(subId); |
| 10671 | if (phone == null) { |
| 10672 | return false; |
| 10673 | } |
| 10674 | final long identity = Binder.clearCallingIdentity(); |
| 10675 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10676 | UiccPort uiccPort = phone.getUiccPort(); |
| 10677 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10678 | return false; |
| 10679 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10680 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10681 | if (uiccProfile == null) { |
| 10682 | return false; |
| 10683 | } |
| 10684 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10685 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10686 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10687 | } |
| 10688 | return false; |
| 10689 | } finally { |
| 10690 | Binder.restoreCallingIdentity(identity); |
| 10691 | } |
| 10692 | } |
| 10693 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10694 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10695 | * Get whether making changes to modem configurations will trigger reboot. |
| 10696 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10697 | */ |
| 10698 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10699 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10700 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10702 | mApp, subId, callingPackage, callingFeatureId, |
| 10703 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10704 | return false; |
| 10705 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10706 | |
| 10707 | enforceTelephonyFeatureWithException(callingPackage, |
| 10708 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10709 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10710 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10711 | final long identity = Binder.clearCallingIdentity(); |
| 10712 | try { |
| 10713 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10714 | } finally { |
| 10715 | Binder.restoreCallingIdentity(identity); |
| 10716 | } |
| 10717 | } |
| 10718 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10719 | private void updateModemStateMetrics() { |
| 10720 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10721 | // TODO: check the state for each modem if the api is ready. |
| 10722 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10723 | } |
| 10724 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10725 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10726 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10727 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10728 | // Verify that the callingPackage belongs to the calling UID |
| 10729 | mApp.getSystemService(AppOpsManager.class) |
| 10730 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10731 | |
| 10732 | enforceTelephonyFeatureWithException(callingPackage, |
| 10733 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10734 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10735 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10736 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10737 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10738 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10739 | if (slotInfos != null) { |
| 10740 | for (int i = 0; i < slotInfos.length; i++) { |
| 10741 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10742 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10743 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10744 | portInfo.getLogicalSlotIndex())); |
| 10745 | } |
| 10746 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10747 | } |
| 10748 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10749 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10750 | } finally { |
| 10751 | Binder.restoreCallingIdentity(identity); |
| 10752 | } |
| 10753 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10754 | |
| 10755 | /** |
| 10756 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10757 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10758 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10759 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10760 | @Override |
| 10761 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10762 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10763 | } |
| 10764 | |
| 10765 | /** |
| 10766 | * Get the HAL Version of a specific service |
| 10767 | */ |
| 10768 | @Override |
| 10769 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10770 | Phone phone = getDefaultPhone(); |
| 10771 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10772 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10773 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10774 | return hv.major * 100 + hv.minor; |
| 10775 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10776 | |
| 10777 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10778 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10779 | * |
| 10780 | * @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] | 10781 | */ |
| 10782 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10783 | public @Nullable String getCurrentPackageName() { |
| 10784 | PackageManager pm = mApp.getPackageManager(); |
| 10785 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10786 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10787 | } |
| 10788 | |
| 10789 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10790 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10791 | * corresponding network requests on a subId. |
| 10792 | * |
| 10793 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10794 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10795 | * 2) APN is un-metered for this subscription, or |
| 10796 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10797 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10798 | * |
| 10799 | * @return whether data is allowed for a apn type. |
| 10800 | * |
| 10801 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10802 | */ |
| 10803 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10804 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10805 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10806 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10807 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10808 | enforceTelephonyFeatureWithException(callingPackage, |
| 10809 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10810 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10811 | // Now that all security checks passes, perform the operation as ourselves. |
| 10812 | final long identity = Binder.clearCallingIdentity(); |
| 10813 | try { |
| 10814 | Phone phone = getPhone(subId); |
| 10815 | if (phone == null) return false; |
| 10816 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10817 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10818 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10819 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10820 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10821 | phone.getServiceState().getDataRoaming()); |
| 10822 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10823 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10824 | } finally { |
| 10825 | Binder.restoreCallingIdentity(identity); |
| 10826 | } |
| 10827 | } |
| 10828 | |
| 10829 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10830 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10831 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10832 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10833 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10834 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10835 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10836 | // Now that all security checks passes, perform the operation as ourselves. |
| 10837 | final long identity = Binder.clearCallingIdentity(); |
| 10838 | try { |
| 10839 | Phone phone = getPhone(subId); |
| 10840 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10841 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10842 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10843 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10844 | } finally { |
| 10845 | Binder.restoreCallingIdentity(identity); |
| 10846 | } |
| 10847 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10848 | |
| 10849 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10850 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10851 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10852 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10853 | |
| 10854 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10855 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10856 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10857 | long token = Binder.clearCallingIdentity(); |
| 10858 | try { |
| 10859 | Phone phone = getPhone(subscriptionId); |
| 10860 | if (phone == null) { |
| 10861 | try { |
| 10862 | if (resultCallback != null) { |
| 10863 | resultCallback.accept(false); |
| 10864 | } |
| 10865 | } catch (RemoteException e) { |
| 10866 | // ignore |
| 10867 | } |
| 10868 | return; |
| 10869 | } |
| 10870 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10871 | Pair.create(specifiers, (x) -> { |
| 10872 | try { |
| 10873 | if (resultCallback != null) { |
| 10874 | resultCallback.accept(x); |
| 10875 | } |
| 10876 | } catch (RemoteException e) { |
| 10877 | // ignore |
| 10878 | } |
| 10879 | }); |
| 10880 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10881 | } finally { |
| 10882 | Binder.restoreCallingIdentity(token); |
| 10883 | } |
| 10884 | } |
| 10885 | |
| 10886 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10887 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10888 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10889 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10890 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10891 | |
| 10892 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10893 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10894 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10895 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10896 | final long identity = Binder.clearCallingIdentity(); |
| 10897 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10898 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10899 | if (result instanceof IllegalStateException) { |
| 10900 | throw (IllegalStateException) result; |
| 10901 | } |
| 10902 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10903 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10904 | return specifiers; |
| 10905 | } finally { |
| 10906 | Binder.restoreCallingIdentity(identity); |
| 10907 | } |
| 10908 | } |
| 10909 | |
| 10910 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10911 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10912 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10913 | |
| 10914 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10915 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10916 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10917 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10918 | } |
| 10919 | |
| 10920 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10921 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10922 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10923 | if (callingPackage == null) { |
| 10924 | callingPackage = getCurrentPackageName(); |
| 10925 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10926 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10927 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10928 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10929 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10930 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10931 | } |
| 10932 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10933 | Intent intent = new Intent(); |
| 10934 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10935 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10936 | // Bring up choose default SMS subscription dialog right now |
| 10937 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10938 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10939 | mApp.startActivity(intent); |
| 10940 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10941 | |
| 10942 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10943 | public void showSwitchToManagedProfileDialog() { |
| 10944 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10945 | try { |
| 10946 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10947 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10948 | // for work telephony. |
| 10949 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10950 | intent.setData(Uri.parse("smsto:")); |
| 10951 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10952 | mApp.startActivity(intent); |
| 10953 | } catch (ActivityNotFoundException e) { |
| 10954 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10955 | Intent intent = new Intent(); |
| 10956 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10957 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10958 | mApp.startActivity(intent); |
| 10959 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10960 | } |
| 10961 | |
| 10962 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10963 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10964 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10965 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 10966 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10967 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10968 | final long identity = Binder.clearCallingIdentity(); |
| 10969 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10970 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10971 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10972 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10973 | return carrierUAProfUrl; |
| 10974 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10975 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10976 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10977 | } finally { |
| 10978 | Binder.restoreCallingIdentity(identity); |
| 10979 | } |
| 10980 | } |
| 10981 | |
| 10982 | @Override |
| 10983 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10984 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10985 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 10986 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10987 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10988 | final long identity = Binder.clearCallingIdentity(); |
| 10989 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10990 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10991 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10992 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10993 | return carrierUserAgent; |
| 10994 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10995 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10996 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10997 | } finally { |
| 10998 | Binder.restoreCallingIdentity(identity); |
| 10999 | } |
| 11000 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11001 | |
| 11002 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11003 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11004 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11005 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11006 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11007 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11008 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11009 | final long identity = Binder.clearCallingIdentity(); |
| 11010 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11011 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11012 | if (phone == null) return false; |
| 11013 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11014 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11015 | } finally { |
| 11016 | Binder.restoreCallingIdentity(identity); |
| 11017 | } |
| 11018 | } |
| 11019 | |
| 11020 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11021 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11022 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11023 | enforceModifyPermission(); |
| 11024 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11025 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11026 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11027 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11028 | final long identity = Binder.clearCallingIdentity(); |
| 11029 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11030 | Phone phone = getPhone(subscriptionId); |
| 11031 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11032 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11033 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11034 | } finally { |
| 11035 | Binder.restoreCallingIdentity(identity); |
| 11036 | } |
| 11037 | } |
| 11038 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11039 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11040 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11041 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11042 | * otherwise. |
| 11043 | */ |
| 11044 | @Override |
| 11045 | public void setCepEnabled(boolean isCepEnabled) { |
| 11046 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11047 | |
| 11048 | final long identity = Binder.clearCallingIdentity(); |
| 11049 | try { |
| 11050 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11051 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11052 | Phone defaultPhone = phone.getImsPhone(); |
| 11053 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11054 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11055 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11056 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11057 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11058 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11059 | + imsPhone.getMsisdn()); |
| 11060 | } |
| 11061 | } |
| 11062 | } finally { |
| 11063 | Binder.restoreCallingIdentity(identity); |
| 11064 | } |
| 11065 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11066 | |
| 11067 | /** |
| 11068 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11069 | * |
| 11070 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11071 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11072 | * before being read. |
| 11073 | */ |
| 11074 | @Override |
| 11075 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11076 | isCompressed) { |
| 11077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11078 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11079 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11080 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11081 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11082 | |
| 11083 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11084 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11085 | Binder.getCallingUserHandle())) { |
| 11086 | if (!isImsAvailableOnDevice()) { |
| 11087 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11088 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11089 | throw new IllegalStateException("IMS not available on device."); |
| 11090 | } |
| 11091 | } else { |
| 11092 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11093 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11094 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11095 | } |
| 11096 | |
| 11097 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11098 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11099 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11100 | } finally { |
| 11101 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11102 | } |
| 11103 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11104 | |
| 11105 | @Override |
| 11106 | public boolean isIccLockEnabled(int subId) { |
| 11107 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11108 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11109 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11110 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11111 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11112 | // Now that all security checks passes, perform the operation as ourselves. |
| 11113 | final long identity = Binder.clearCallingIdentity(); |
| 11114 | try { |
| 11115 | Phone phone = getPhone(subId); |
| 11116 | if (phone != null && phone.getIccCard() != null) { |
| 11117 | return phone.getIccCard().getIccLockEnabled(); |
| 11118 | } else { |
| 11119 | return false; |
| 11120 | } |
| 11121 | } finally { |
| 11122 | Binder.restoreCallingIdentity(identity); |
| 11123 | } |
| 11124 | } |
| 11125 | |
| 11126 | /** |
| 11127 | * Set the ICC pin lock enabled or disabled. |
| 11128 | * |
| 11129 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11130 | * three cases: |
| 11131 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11132 | * successfully. |
| 11133 | * - Positive number and zero for remaining password attempts. |
| 11134 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11135 | * |
| 11136 | */ |
| 11137 | @Override |
| 11138 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11139 | enforceModifyPermission(); |
| 11140 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11141 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11142 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11143 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11144 | Phone phone = getPhone(subId); |
| 11145 | if (phone == null) { |
| 11146 | return 0; |
| 11147 | } |
| 11148 | // Now that all security checks passes, perform the operation as ourselves. |
| 11149 | final long identity = Binder.clearCallingIdentity(); |
| 11150 | try { |
| 11151 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11152 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11153 | return attemptsRemaining; |
| 11154 | |
| 11155 | } catch (Exception e) { |
| 11156 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11157 | } finally { |
| 11158 | Binder.restoreCallingIdentity(identity); |
| 11159 | } |
| 11160 | return 0; |
| 11161 | } |
| 11162 | |
| 11163 | /** |
| 11164 | * Change the ICC password used in ICC pin lock. |
| 11165 | * |
| 11166 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11167 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11168 | * - Positive number and zero for remaining password attempts. |
| 11169 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11170 | * |
| 11171 | */ |
| 11172 | @Override |
| 11173 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11174 | enforceModifyPermission(); |
| 11175 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11176 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11177 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11178 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11179 | Phone phone = getPhone(subId); |
| 11180 | if (phone == null) { |
| 11181 | return 0; |
| 11182 | } |
| 11183 | // Now that all security checks passes, perform the operation as ourselves. |
| 11184 | final long identity = Binder.clearCallingIdentity(); |
| 11185 | try { |
| 11186 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11187 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11188 | return attemptsRemaining; |
| 11189 | |
| 11190 | } catch (Exception e) { |
| 11191 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11192 | } finally { |
| 11193 | Binder.restoreCallingIdentity(identity); |
| 11194 | } |
| 11195 | return 0; |
| 11196 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11197 | |
| 11198 | /** |
| 11199 | * Request for receiving user activity notification |
| 11200 | */ |
| 11201 | @Override |
| 11202 | public void requestUserActivityNotification() { |
| 11203 | if (!mNotifyUserActivity.get() |
| 11204 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11205 | mNotifyUserActivity.set(true); |
| 11206 | } |
| 11207 | } |
| 11208 | |
| 11209 | /** |
| 11210 | * Called when userActivity is signalled in the power manager. |
| 11211 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11212 | */ |
| 11213 | @Override |
| 11214 | public void userActivity() { |
| 11215 | // *************************************** |
| 11216 | // * Inherited from PhoneWindowManager * |
| 11217 | // *************************************** |
| 11218 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11219 | // WITH ITS LOCKS HELD. |
| 11220 | // |
| 11221 | // This code must be VERY careful about the locks |
| 11222 | // it acquires. |
| 11223 | // In fact, the current code acquires way too many, |
| 11224 | // and probably has lurking deadlocks. |
| 11225 | |
| 11226 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11227 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11228 | } |
| 11229 | |
| 11230 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11231 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11232 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11233 | } |
| 11234 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11235 | |
| 11236 | @Override |
| 11237 | public boolean canConnectTo5GInDsdsMode() { |
| 11238 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11239 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11240 | |
| 11241 | @Override |
| 11242 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11243 | String callingFeatureId) { |
| 11244 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11245 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11246 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11247 | } |
| 11248 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11249 | enforceTelephonyFeatureWithException(callingPackage, |
| 11250 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11251 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11252 | Phone phone = getPhone(subId); |
| 11253 | if (phone == null) { |
| 11254 | throw new RuntimeException("phone is not available"); |
| 11255 | } |
| 11256 | // Now that all security checks passes, perform the operation as ourselves. |
| 11257 | final long identity = Binder.clearCallingIdentity(); |
| 11258 | try { |
| 11259 | return phone.getEquivalentHomePlmns(); |
| 11260 | } finally { |
| 11261 | Binder.restoreCallingIdentity(identity); |
| 11262 | } |
| 11263 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11264 | |
| 11265 | @Override |
| 11266 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11267 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11268 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11269 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11270 | "isRadioInterfaceCapabilitySupported"); |
| 11271 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11272 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11273 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11274 | if (radioInterfaceCapabilities == null) { |
| 11275 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11276 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11277 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11278 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11279 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11280 | @Override |
| 11281 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11282 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11283 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11284 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11285 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11286 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11287 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11288 | |
| 11289 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11290 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11291 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11292 | if (DBG) { |
| 11293 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11294 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11295 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11296 | } |
| 11297 | |
| 11298 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11299 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11300 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11301 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11302 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11303 | if (callback != null) { |
| 11304 | try { |
| 11305 | callback.onAuthenticationFailure( |
| 11306 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11307 | } catch (RemoteException exception) { |
| 11308 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11309 | } |
| 11310 | return; |
| 11311 | } |
| 11312 | } |
| 11313 | |
| 11314 | final long token = Binder.clearCallingIdentity(); |
| 11315 | try { |
| 11316 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11317 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11318 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11319 | } finally { |
| 11320 | Binder.restoreCallingIdentity(token); |
| 11321 | } |
| 11322 | } |
| 11323 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11324 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11325 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11326 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11327 | * requested radio power state will actually be set. See {@link |
| 11328 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11329 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11330 | * @param enable {@code true} if trying to turn radio on. |
| 11331 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11332 | * false}. |
| 11333 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11334 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11335 | boolean isPhoneAvailable = false; |
| 11336 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11337 | Phone phone = PhoneFactory.getPhone(i); |
| 11338 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11339 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11340 | isPhoneAvailable = true; |
| 11341 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11342 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11343 | |
| 11344 | // return true if successfully informed the phone object about the thermal radio power |
| 11345 | // request. |
| 11346 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11347 | } |
| 11348 | |
| 11349 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11350 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11351 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11352 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11353 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11354 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11355 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11356 | } |
| 11357 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11358 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11359 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11360 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11361 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11362 | } |
| 11363 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11364 | setDataEnabledForReason( |
| 11365 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11366 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11367 | if (isDataThrottlingSupported) { |
| 11368 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11369 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11370 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11371 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11372 | } else if (thermalMitigationResult |
| 11373 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11374 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11375 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11376 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11377 | } |
| 11378 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11379 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11380 | |
| 11381 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11382 | } |
| 11383 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11384 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11385 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11386 | for (String pckg : context.getResources() |
| 11387 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11388 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11389 | } |
| 11390 | } |
| 11391 | |
| 11392 | return sThermalMitigationAllowlistedPackages; |
| 11393 | } |
| 11394 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11395 | private boolean isAnyPhoneInEmergencyState() { |
| 11396 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11397 | if (tm.isInEmergencyCall()) { |
| 11398 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11399 | return true; |
| 11400 | } |
| 11401 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11402 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11403 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11404 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11405 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11406 | return true; |
| 11407 | } |
| 11408 | } |
| 11409 | |
| 11410 | return false; |
| 11411 | } |
| 11412 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11413 | /** |
| 11414 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11415 | * @param packageName name of package to be allowlisted |
| 11416 | * @param context |
| 11417 | */ |
| 11418 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11419 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11420 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11421 | } |
| 11422 | |
| 11423 | /** |
| 11424 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11425 | * @param packageName name of package to remove from allowlist |
| 11426 | * @param context |
| 11427 | */ |
| 11428 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11429 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11430 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11431 | } |
| 11432 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11433 | /** |
| 11434 | * Thermal mitigation request to control functionalities at modem. |
| 11435 | * |
| 11436 | * @param subId the id of the subscription. |
| 11437 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11438 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11439 | * |
| 11440 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11441 | */ |
| 11442 | @Override |
| 11443 | @ThermalMitigationResult |
| 11444 | public int sendThermalMitigationRequest( |
| 11445 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11446 | ThermalMitigationRequest thermalMitigationRequest, |
| 11447 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11448 | enforceModifyPermission(); |
| 11449 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11450 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11451 | |
| 11452 | enforceTelephonyFeatureWithException(callingPackage, |
| 11453 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11454 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11455 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11456 | .contains(callingPackage)) { |
| 11457 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11458 | + "calling package: " + callingPackage); |
| 11459 | } |
| 11460 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11461 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11462 | final long identity = Binder.clearCallingIdentity(); |
| 11463 | |
| 11464 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11465 | try { |
| 11466 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11467 | switch (thermalMitigationAction) { |
| 11468 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11469 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11470 | handleDataThrottlingRequest(subId, |
| 11471 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11472 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11473 | break; |
| 11474 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11475 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11476 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11477 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11478 | } |
| 11479 | |
| 11480 | // Ensure that radio is on. If not able to power on due to phone being |
| 11481 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11482 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11483 | thermalMitigationResult = |
| 11484 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11485 | break; |
| 11486 | } |
| 11487 | |
| 11488 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11489 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11490 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11491 | break; |
| 11492 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11493 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11494 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11495 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11496 | } |
| 11497 | |
| 11498 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11499 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11500 | Phone phone = getPhone(subId); |
| 11501 | if (phone == null) { |
| 11502 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11503 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11504 | break; |
| 11505 | } |
| 11506 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11507 | TelephonyConnectionService service = |
| 11508 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11509 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11510 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11511 | thermalMitigationResult = |
| 11512 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11513 | break; |
| 11514 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11515 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11516 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11517 | break; |
| 11518 | } |
| 11519 | } else { |
| 11520 | thermalMitigationResult = |
| 11521 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11522 | break; |
| 11523 | } |
| 11524 | |
| 11525 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11526 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11527 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11528 | thermalMitigationResult = |
| 11529 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11530 | break; |
| 11531 | } |
| 11532 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11533 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11534 | break; |
| 11535 | default: |
| 11536 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11537 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11538 | } |
| 11539 | } catch (IllegalArgumentException e) { |
| 11540 | throw e; |
| 11541 | } catch (Exception e) { |
| 11542 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11543 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11544 | } finally { |
| 11545 | Binder.restoreCallingIdentity(identity); |
| 11546 | } |
| 11547 | |
| 11548 | if (DBG) { |
| 11549 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11550 | + thermalMitigationResult); |
| 11551 | } |
| 11552 | |
| 11553 | return thermalMitigationResult; |
| 11554 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11555 | |
| 11556 | /** |
| 11557 | * Set the GbaService Package Name that Telephony will bind to. |
| 11558 | * |
| 11559 | * @param subId The sim that the GbaService is associated with. |
| 11560 | * @param packageName The name of the package to be replaced with. |
| 11561 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11562 | */ |
| 11563 | @Override |
| 11564 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11565 | enforceModifyPermission(); |
| 11566 | |
| 11567 | final long identity = Binder.clearCallingIdentity(); |
| 11568 | try { |
| 11569 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11570 | } finally { |
| 11571 | Binder.restoreCallingIdentity(identity); |
| 11572 | } |
| 11573 | } |
| 11574 | |
| 11575 | /** |
| 11576 | * Return the package name of the currently bound GbaService. |
| 11577 | * |
| 11578 | * @param subId The sim that the GbaService is associated with. |
| 11579 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11580 | */ |
| 11581 | @Override |
| 11582 | public String getBoundGbaService(int subId) { |
| 11583 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11584 | |
| 11585 | final long identity = Binder.clearCallingIdentity(); |
| 11586 | try { |
| 11587 | return getGbaManager(subId).getServicePackage(); |
| 11588 | } finally { |
| 11589 | Binder.restoreCallingIdentity(identity); |
| 11590 | } |
| 11591 | } |
| 11592 | |
| 11593 | /** |
| 11594 | * Set the release time for telephony to unbind GbaService. |
| 11595 | * |
| 11596 | * @param subId The sim that the GbaService is associated with. |
| 11597 | * @param interval The release time to unbind GbaService by millisecond. |
| 11598 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11599 | */ |
| 11600 | @Override |
| 11601 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11602 | enforceModifyPermission(); |
| 11603 | |
| 11604 | final long identity = Binder.clearCallingIdentity(); |
| 11605 | try { |
| 11606 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11607 | } finally { |
| 11608 | Binder.restoreCallingIdentity(identity); |
| 11609 | } |
| 11610 | } |
| 11611 | |
| 11612 | /** |
| 11613 | * Return the release time for telephony to unbind GbaService. |
| 11614 | * |
| 11615 | * @param subId The sim that the GbaService is associated with. |
| 11616 | * @return The release time to unbind GbaService by millisecond. |
| 11617 | */ |
| 11618 | @Override |
| 11619 | public int getGbaReleaseTime(int subId) { |
| 11620 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11621 | |
| 11622 | final long identity = Binder.clearCallingIdentity(); |
| 11623 | try { |
| 11624 | return getGbaManager(subId).getReleaseTime(); |
| 11625 | } finally { |
| 11626 | Binder.restoreCallingIdentity(identity); |
| 11627 | } |
| 11628 | } |
| 11629 | |
| 11630 | private GbaManager getGbaManager(int subId) { |
| 11631 | GbaManager instance = GbaManager.getInstance(subId); |
| 11632 | if (instance == null) { |
| 11633 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11634 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11635 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11636 | } |
| 11637 | return instance; |
| 11638 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11639 | |
| 11640 | /** |
| 11641 | * indicate whether the device and the carrier can support |
| 11642 | * RCS VoLTE single registration. |
| 11643 | */ |
| 11644 | @Override |
| 11645 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11646 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11647 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11648 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11649 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11650 | |
| 11651 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11652 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11653 | } |
| 11654 | |
| 11655 | final long identity = Binder.clearCallingIdentity(); |
| 11656 | try { |
| 11657 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11658 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11659 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11660 | if (isCapable != null) { |
| 11661 | return isCapable; |
| 11662 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11663 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11664 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11665 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11666 | } finally { |
| 11667 | Binder.restoreCallingIdentity(identity); |
| 11668 | } |
| 11669 | } |
| 11670 | |
| 11671 | /** |
| 11672 | * Register RCS provisioning callback. |
| 11673 | */ |
| 11674 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11675 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11676 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11677 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11678 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11679 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11680 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11681 | |
| 11682 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11683 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11684 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11685 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11686 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11687 | Binder.getCallingUserHandle())) { |
| 11688 | if (!isImsAvailableOnDevice()) { |
| 11689 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11690 | "IMS not available on device."); |
| 11691 | } |
| 11692 | } else { |
| 11693 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11694 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11695 | } |
| 11696 | |
| 11697 | final long identity = Binder.clearCallingIdentity(); |
| 11698 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11699 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11700 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11701 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11702 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11703 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11704 | } finally { |
| 11705 | Binder.restoreCallingIdentity(identity); |
| 11706 | } |
| 11707 | } |
| 11708 | |
| 11709 | /** |
| 11710 | * Unregister RCS provisioning callback. |
| 11711 | */ |
| 11712 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11713 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11714 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11715 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11716 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11717 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11718 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11719 | |
| 11720 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11721 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11722 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11723 | |
| 11724 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11725 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11726 | Binder.getCallingUserHandle())) { |
| 11727 | if (!isImsAvailableOnDevice()) { |
| 11728 | // operation failed silently |
| 11729 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11730 | return; |
| 11731 | } |
| 11732 | } else { |
| 11733 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11734 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11735 | "unregisterRcsProvisioningCallback"); |
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 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11741 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11742 | } finally { |
| 11743 | Binder.restoreCallingIdentity(identity); |
| 11744 | } |
| 11745 | } |
| 11746 | |
| 11747 | /** |
| 11748 | * trigger RCS reconfiguration. |
| 11749 | */ |
| 11750 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11751 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11752 | "triggerRcsReconfiguration", |
| 11753 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11754 | |
| 11755 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11756 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11757 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11758 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11759 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11760 | Binder.getCallingUserHandle())) { |
| 11761 | if (!isImsAvailableOnDevice()) { |
| 11762 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11763 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11764 | throw new IllegalStateException("IMS not available on device."); |
| 11765 | } |
| 11766 | } else { |
| 11767 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11768 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11769 | } |
| 11770 | |
| 11771 | final long identity = Binder.clearCallingIdentity(); |
| 11772 | try { |
| 11773 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11774 | } finally { |
| 11775 | Binder.restoreCallingIdentity(identity); |
| 11776 | } |
| 11777 | } |
| 11778 | |
| 11779 | /** |
| 11780 | * Provide the client configuration parameters of the RCS application. |
| 11781 | */ |
| 11782 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11783 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11784 | "setRcsClientConfiguration", |
| 11785 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11786 | |
| 11787 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11788 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11789 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11790 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11791 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11792 | Binder.getCallingUserHandle())) { |
| 11793 | if (!isImsAvailableOnDevice()) { |
| 11794 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11795 | "IMS not available on device."); |
| 11796 | } |
| 11797 | } else { |
| 11798 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11799 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11800 | } |
| 11801 | |
| 11802 | final long identity = Binder.clearCallingIdentity(); |
| 11803 | |
| 11804 | try { |
| 11805 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11806 | if (configBinder == null) { |
| 11807 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11808 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11809 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11810 | } else { |
| 11811 | configBinder.setRcsClientConfiguration(rcc); |
| 11812 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11813 | |
| 11814 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11815 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11816 | } catch (RemoteException e) { |
| 11817 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11818 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11819 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11820 | } finally { |
| 11821 | Binder.restoreCallingIdentity(identity); |
| 11822 | } |
| 11823 | } |
| 11824 | |
| 11825 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11826 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11827 | */ |
| 11828 | @Override |
| 11829 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11830 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11831 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11832 | |
| 11833 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11834 | } |
| 11835 | |
| 11836 | /** |
| 11837 | * Gets the test mode for RCS VoLTE single registration. |
| 11838 | */ |
| 11839 | @Override |
| 11840 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11841 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11842 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11843 | |
| 11844 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11845 | } |
| 11846 | |
| 11847 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11848 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11849 | */ |
| 11850 | @Override |
| 11851 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11852 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11853 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11854 | enforceModifyPermission(); |
| 11855 | |
| 11856 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11857 | : Boolean.parseBoolean(enabledStr); |
| 11858 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11859 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11860 | } |
| 11861 | |
| 11862 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11863 | * Sends a device to device communication message. Only usable via shell. |
| 11864 | * @param message message to send. |
| 11865 | * @param value message value. |
| 11866 | */ |
| 11867 | @Override |
| 11868 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11869 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11870 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11871 | enforceModifyPermission(); |
| 11872 | |
| 11873 | final long identity = Binder.clearCallingIdentity(); |
| 11874 | try { |
| 11875 | TelephonyConnectionService service = |
| 11876 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11877 | if (service == null) { |
| 11878 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11879 | return; |
| 11880 | } |
| 11881 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11882 | } finally { |
| 11883 | Binder.restoreCallingIdentity(identity); |
| 11884 | } |
| 11885 | } |
| 11886 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11887 | /** |
| 11888 | * Sets the specified device to device transport active. |
| 11889 | * @param transport The transport to set active. |
| 11890 | */ |
| 11891 | @Override |
| 11892 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11893 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11894 | "setActiveDeviceToDeviceTransport"); |
| 11895 | enforceModifyPermission(); |
| 11896 | |
| 11897 | final long identity = Binder.clearCallingIdentity(); |
| 11898 | try { |
| 11899 | TelephonyConnectionService service = |
| 11900 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11901 | if (service == null) { |
| 11902 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11903 | return; |
| 11904 | } |
| 11905 | service.setActiveDeviceToDeviceTransport(transport); |
| 11906 | } finally { |
| 11907 | Binder.restoreCallingIdentity(identity); |
| 11908 | } |
| 11909 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11910 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11911 | @Override |
| 11912 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11913 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11914 | "setDeviceToDeviceForceEnabled"); |
| 11915 | |
| 11916 | final long identity = Binder.clearCallingIdentity(); |
| 11917 | try { |
| 11918 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11919 | p -> { |
| 11920 | Phone thePhone = p.getImsPhone(); |
| 11921 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11922 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11923 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11924 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11925 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11926 | (ImsPhoneCallTracker) tracker; |
| 11927 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11928 | } |
| 11929 | } |
| 11930 | } |
| 11931 | ); |
| 11932 | } finally { |
| 11933 | Binder.restoreCallingIdentity(identity); |
| 11934 | } |
| 11935 | } |
| 11936 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11937 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11938 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11939 | */ |
| 11940 | @Override |
| 11941 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11942 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11943 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11944 | } |
| 11945 | |
| 11946 | /** |
| 11947 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11948 | */ |
| 11949 | @Override |
| 11950 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11951 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11952 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11953 | enforceModifyPermission(); |
| 11954 | |
| 11955 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11956 | : Boolean.parseBoolean(enabledStr); |
| 11957 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11958 | subId, enabled); |
| 11959 | } |
| 11960 | |
| 11961 | /** |
| 11962 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11963 | */ |
| 11964 | @Override |
| 11965 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11966 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11967 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11968 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11969 | |
| 11970 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11971 | * Overrides the ims feature validation result |
| 11972 | */ |
| 11973 | @Override |
| 11974 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11975 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11976 | "setImsFeatureValidationOverride"); |
| 11977 | |
| 11978 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11979 | : Boolean.parseBoolean(enabledStr); |
| 11980 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11981 | subId, enabled); |
| 11982 | } |
| 11983 | |
| 11984 | /** |
| 11985 | * Gets the ims feature validation override value |
| 11986 | */ |
| 11987 | @Override |
| 11988 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11989 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11990 | "getImsFeatureValidationOverride"); |
| 11991 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11992 | } |
| 11993 | |
| 11994 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11995 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11996 | * their mobile plan. |
| 11997 | */ |
| 11998 | @Override |
| 11999 | public String getMobileProvisioningUrl() { |
| 12000 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12001 | final long identity = Binder.clearCallingIdentity(); |
| 12002 | try { |
| 12003 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12004 | } finally { |
| 12005 | Binder.restoreCallingIdentity(identity); |
| 12006 | } |
| 12007 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12008 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12009 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12010 | * Get the EAB contact from the EAB database. |
| 12011 | */ |
| 12012 | @Override |
| 12013 | public String getContactFromEab(String contact) { |
| 12014 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12015 | enforceModifyPermission(); |
| 12016 | final long identity = Binder.clearCallingIdentity(); |
| 12017 | try { |
| 12018 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12019 | } finally { |
| 12020 | Binder.restoreCallingIdentity(identity); |
| 12021 | } |
| 12022 | } |
| 12023 | |
| 12024 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12025 | * Get the EAB capability from the EAB database. |
| 12026 | */ |
| 12027 | @Override |
| 12028 | public String getCapabilityFromEab(String contact) { |
| 12029 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12030 | enforceModifyPermission(); |
| 12031 | final long identity = Binder.clearCallingIdentity(); |
| 12032 | try { |
| 12033 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12034 | } finally { |
| 12035 | Binder.restoreCallingIdentity(identity); |
| 12036 | } |
| 12037 | } |
| 12038 | |
| 12039 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12040 | * Remove the EAB contacts from the EAB database. |
| 12041 | */ |
| 12042 | @Override |
| 12043 | public int removeContactFromEab(int subId, String contacts) { |
| 12044 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12045 | enforceModifyPermission(); |
| 12046 | final long identity = Binder.clearCallingIdentity(); |
| 12047 | try { |
| 12048 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12049 | } finally { |
| 12050 | Binder.restoreCallingIdentity(identity); |
| 12051 | } |
| 12052 | } |
| 12053 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12054 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12055 | public boolean getDeviceUceEnabled() { |
| 12056 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12057 | final long identity = Binder.clearCallingIdentity(); |
| 12058 | try { |
| 12059 | return mApp.getDeviceUceEnabled(); |
| 12060 | } finally { |
| 12061 | Binder.restoreCallingIdentity(identity); |
| 12062 | } |
| 12063 | } |
| 12064 | |
| 12065 | @Override |
| 12066 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12067 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12068 | final long identity = Binder.clearCallingIdentity(); |
| 12069 | try { |
| 12070 | mApp.setDeviceUceEnabled(isEnabled); |
| 12071 | } finally { |
| 12072 | Binder.restoreCallingIdentity(identity); |
| 12073 | } |
| 12074 | } |
| 12075 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12076 | /** |
| 12077 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12078 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12079 | */ |
| 12080 | // Used for SHELL command only right now. |
| 12081 | @Override |
| 12082 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12083 | List<String> featureTags) { |
| 12084 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12085 | "addUceRegistrationOverrideShell"); |
| 12086 | final long identity = Binder.clearCallingIdentity(); |
| 12087 | try { |
| 12088 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12089 | new ArraySet<>(featureTags)); |
| 12090 | } catch (ImsException e) { |
| 12091 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12092 | } finally { |
| 12093 | Binder.restoreCallingIdentity(identity); |
| 12094 | } |
| 12095 | } |
| 12096 | |
| 12097 | /** |
| 12098 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12099 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12100 | */ |
| 12101 | // Used for SHELL command only right now. |
| 12102 | @Override |
| 12103 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12104 | List<String> featureTags) { |
| 12105 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12106 | "removeUceRegistrationOverrideShell"); |
| 12107 | final long identity = Binder.clearCallingIdentity(); |
| 12108 | try { |
| 12109 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12110 | new ArraySet<>(featureTags)); |
| 12111 | } catch (ImsException e) { |
| 12112 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12113 | } finally { |
| 12114 | Binder.restoreCallingIdentity(identity); |
| 12115 | } |
| 12116 | } |
| 12117 | |
| 12118 | /** |
| 12119 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12120 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12121 | */ |
| 12122 | // Used for SHELL command only right now. |
| 12123 | @Override |
| 12124 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12125 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12126 | "clearUceRegistrationOverrideShell"); |
| 12127 | final long identity = Binder.clearCallingIdentity(); |
| 12128 | try { |
| 12129 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12130 | } catch (ImsException e) { |
| 12131 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12132 | } finally { |
| 12133 | Binder.restoreCallingIdentity(identity); |
| 12134 | } |
| 12135 | } |
| 12136 | |
| 12137 | /** |
| 12138 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12139 | */ |
| 12140 | // Used for SHELL command only right now. |
| 12141 | @Override |
| 12142 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12143 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12144 | "getLatestRcsContactUceCapabilityShell"); |
| 12145 | final long identity = Binder.clearCallingIdentity(); |
| 12146 | try { |
| 12147 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12148 | } catch (ImsException e) { |
| 12149 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12150 | } finally { |
| 12151 | Binder.restoreCallingIdentity(identity); |
| 12152 | } |
| 12153 | } |
| 12154 | |
| 12155 | /** |
| 12156 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12157 | * device does not have an active PUBLISH. |
| 12158 | */ |
| 12159 | // Used for SHELL command only right now. |
| 12160 | @Override |
| 12161 | public String getLastUcePidfXmlShell(int subId) { |
| 12162 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12163 | final long identity = Binder.clearCallingIdentity(); |
| 12164 | try { |
| 12165 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12166 | } catch (ImsException e) { |
| 12167 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12168 | } finally { |
| 12169 | Binder.restoreCallingIdentity(identity); |
| 12170 | } |
| 12171 | } |
| 12172 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12173 | /** |
| 12174 | * Remove UCE requests cannot be sent to the network status. |
| 12175 | */ |
| 12176 | // Used for SHELL command only right now. |
| 12177 | @Override |
| 12178 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12179 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12180 | final long identity = Binder.clearCallingIdentity(); |
| 12181 | try { |
| 12182 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12183 | } catch (ImsException e) { |
| 12184 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12185 | } finally { |
| 12186 | Binder.restoreCallingIdentity(identity); |
| 12187 | } |
| 12188 | } |
| 12189 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12190 | /** |
| 12191 | * Remove UCE requests cannot be sent to the network status. |
| 12192 | */ |
| 12193 | // Used for SHELL command only. |
| 12194 | @Override |
| 12195 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12196 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12197 | final long identity = Binder.clearCallingIdentity(); |
| 12198 | try { |
| 12199 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12200 | } catch (ImsException e) { |
| 12201 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12202 | } finally { |
| 12203 | Binder.restoreCallingIdentity(identity); |
| 12204 | } |
| 12205 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12206 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12207 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12208 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12209 | String callingPackage) { |
| 12210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12211 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12212 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12213 | enforceTelephonyFeatureWithException(callingPackage, |
| 12214 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12215 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12216 | final int callingUid = Binder.getCallingUid(); |
| 12217 | // Verify that tha callingPackage belongs to the calling UID |
| 12218 | mApp.getSystemService(AppOpsManager.class) |
| 12219 | .checkPackage(callingUid, callingPackage); |
| 12220 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12221 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12222 | |
| 12223 | final long identity = Binder.clearCallingIdentity(); |
| 12224 | try { |
| 12225 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12226 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12227 | |
| 12228 | if (result instanceof IllegalStateException) { |
| 12229 | throw (IllegalStateException) result; |
| 12230 | } |
| 12231 | } finally { |
| 12232 | Binder.restoreCallingIdentity(identity); |
| 12233 | } |
| 12234 | } |
| 12235 | |
| 12236 | @Override |
| 12237 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12238 | String callingPackage) { |
| 12239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12240 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12241 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12242 | enforceTelephonyFeatureWithException(callingPackage, |
| 12243 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12244 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12245 | final int callingUid = Binder.getCallingUid(); |
| 12246 | // Verify that tha callingPackage belongs to the calling UID |
| 12247 | mApp.getSystemService(AppOpsManager.class) |
| 12248 | .checkPackage(callingUid, callingPackage); |
| 12249 | |
| 12250 | final long identity = Binder.clearCallingIdentity(); |
| 12251 | try { |
| 12252 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12253 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12254 | |
| 12255 | if (result instanceof IllegalStateException) { |
| 12256 | throw (IllegalStateException) result; |
| 12257 | } |
| 12258 | } finally { |
| 12259 | Binder.restoreCallingIdentity(identity); |
| 12260 | } |
| 12261 | } |
| 12262 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12263 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12264 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12265 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12266 | // phone/system process do not have further restriction on request |
| 12267 | return; |
| 12268 | } |
| 12269 | |
| 12270 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12271 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12272 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12273 | context.enforceCallingOrSelfPermission( |
| 12274 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12275 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12276 | } |
| 12277 | |
| 12278 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12279 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12280 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12281 | || info.isEnabled()) { |
| 12282 | throw new IllegalArgumentException( |
| 12283 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12284 | } |
| 12285 | |
| 12286 | // Thresholds length for each RAN need in range. This has been validated in |
| 12287 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12288 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12289 | final int[] thresholds = info.getThresholds(); |
| 12290 | Objects.requireNonNull(thresholds); |
| 12291 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12292 | || thresholds.length |
| 12293 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12294 | throw new IllegalArgumentException( |
| 12295 | "thresholds length is out of range: " + thresholds.length); |
| 12296 | } |
| 12297 | } |
| 12298 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12299 | |
| 12300 | /** |
| 12301 | * Gets the current phone capability. |
| 12302 | * |
| 12303 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12304 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12305 | * It's used to evaluate possible phone config change, for example from single |
| 12306 | * SIM device to multi-SIM device. |
| 12307 | */ |
| 12308 | @Override |
| 12309 | public PhoneCapability getPhoneCapability() { |
| 12310 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12311 | |
| 12312 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12313 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12314 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12315 | final long identity = Binder.clearCallingIdentity(); |
| 12316 | try { |
| 12317 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12318 | } finally { |
| 12319 | Binder.restoreCallingIdentity(identity); |
| 12320 | } |
| 12321 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12322 | |
| 12323 | /** |
| 12324 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12325 | * required to be done shortly after the API is invoked. |
| 12326 | */ |
| 12327 | @Override |
| 12328 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12329 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12330 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12331 | enforceRebootPermission(); |
| 12332 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12333 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12334 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12335 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12336 | final long identity = Binder.clearCallingIdentity(); |
| 12337 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12338 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12339 | } finally { |
| 12340 | Binder.restoreCallingIdentity(identity); |
| 12341 | } |
| 12342 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12343 | |
| 12344 | /** |
| 12345 | * Request to get the current slicing configuration including URSP rules and |
| 12346 | * NSSAIs (configured, allowed and rejected). |
| 12347 | * |
| 12348 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12349 | */ |
| 12350 | @Override |
| 12351 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12352 | TelephonyPermissions |
| 12353 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12354 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12355 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12356 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12357 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12358 | "getSlicingConfig"); |
| 12359 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12360 | final long identity = Binder.clearCallingIdentity(); |
| 12361 | try { |
| 12362 | Phone phone = getDefaultPhone(); |
| 12363 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12364 | } finally { |
| 12365 | Binder.restoreCallingIdentity(identity); |
| 12366 | } |
| 12367 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12368 | |
| 12369 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12370 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12371 | * |
| 12372 | * @param capability The premium capability to check. |
| 12373 | * @param subId The subId to check the premium capability for. |
| 12374 | * |
| 12375 | * @return Whether the given premium capability is available to purchase. |
| 12376 | */ |
| 12377 | @Override |
| 12378 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12379 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12380 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12381 | log("Premium capability " |
| 12382 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12383 | + " is not available for purchase due to missing permissions."); |
| 12384 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12385 | + "permission READ_BASIC_PHONE_STATE."); |
| 12386 | } |
| 12387 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12388 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12389 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12390 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12391 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12392 | if (phone == null) { |
| 12393 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12394 | return false; |
| 12395 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12396 | final long identity = Binder.clearCallingIdentity(); |
| 12397 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12398 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12399 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12400 | } finally { |
| 12401 | Binder.restoreCallingIdentity(identity); |
| 12402 | } |
| 12403 | } |
| 12404 | |
| 12405 | /** |
| 12406 | * Purchase the given premium capability from the carrier. |
| 12407 | * |
| 12408 | * @param capability The premium capability to purchase. |
| 12409 | * @param callback The result of the purchase request. |
| 12410 | * @param subId The subId to purchase the premium capability for. |
| 12411 | */ |
| 12412 | @Override |
| 12413 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12414 | log("purchasePremiumCapability: capability=" |
| 12415 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12416 | + getCurrentPackageName()); |
| 12417 | |
| 12418 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12419 | mApp, "purchasePremiumCapability")) { |
| 12420 | log("purchasePremiumCapability " |
| 12421 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12422 | + " failed due to missing permissions."); |
| 12423 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12424 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12425 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12426 | mApp, "purchasePremiumCapability")) { |
| 12427 | log("purchasePremiumCapability " |
| 12428 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12429 | + " failed due to missing permissions."); |
| 12430 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12431 | } |
| 12432 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12433 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12434 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12435 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12436 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12437 | if (phone == null) { |
| 12438 | try { |
| 12439 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12440 | callback.accept(result); |
| 12441 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12442 | } catch (RemoteException e) { |
| 12443 | String logStr = "Purchase premium capability " |
| 12444 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12445 | + " failed due to RemoteException handling null phone: " + e; |
| 12446 | if (DBG) log(logStr); |
| 12447 | AnomalyReporter.reportAnomaly( |
| 12448 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12449 | } |
| 12450 | return; |
| 12451 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12452 | |
| 12453 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12454 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12455 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12456 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12457 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12458 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12459 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12460 | |
| 12461 | boolean isVisible = false; |
| 12462 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12463 | if (am != null) { |
| 12464 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12465 | if (processes != null) { |
| 12466 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12467 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12468 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12469 | if (process.processName.equals(callingProcess) && process.importance |
| 12470 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12471 | isVisible = true; |
| 12472 | break; |
| 12473 | } |
| 12474 | } |
| 12475 | } |
| 12476 | } |
| 12477 | |
| 12478 | if (!isVisible) { |
| 12479 | try { |
| 12480 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12481 | callback.accept(result); |
| 12482 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12483 | } catch (RemoteException e) { |
| 12484 | String logStr = "Purchase premium capability " |
| 12485 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12486 | + " failed due to RemoteException handling background application: " + e; |
| 12487 | if (DBG) log(logStr); |
| 12488 | AnomalyReporter.reportAnomaly( |
| 12489 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12490 | } |
| 12491 | return; |
| 12492 | } |
| 12493 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12494 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12495 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12496 | } |
| 12497 | |
| 12498 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12499 | * Register an IMS connection state callback |
| 12500 | */ |
| 12501 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12502 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12503 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12504 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12505 | // ImsMmTelManager |
| 12506 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12507 | TelephonyPermissions |
| 12508 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12509 | mApp, subId, "registerImsStateCallback"); |
| 12510 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12511 | // ImsRcsManager or SipDelegateManager |
| 12512 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12513 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12514 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12515 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12516 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12517 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12518 | } |
| 12519 | |
| 12520 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12521 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12522 | "IMS not available on device."); |
| 12523 | } |
| 12524 | |
| 12525 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12526 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12527 | } |
| 12528 | |
| 12529 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12530 | if (controller == null) { |
| 12531 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12532 | "IMS not available on device."); |
| 12533 | } |
| 12534 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12535 | if (callingPackage == null) { |
| 12536 | callingPackage = getCurrentPackageName(); |
| 12537 | } |
| 12538 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12539 | final long token = Binder.clearCallingIdentity(); |
| 12540 | try { |
| 12541 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12542 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12543 | } catch (ImsException e) { |
| 12544 | throw new ServiceSpecificException(e.getCode()); |
| 12545 | } finally { |
| 12546 | Binder.restoreCallingIdentity(token); |
| 12547 | } |
| 12548 | } |
| 12549 | |
| 12550 | /** |
| 12551 | * Unregister an IMS connection state callback |
| 12552 | */ |
| 12553 | @Override |
| 12554 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12555 | final long token = Binder.clearCallingIdentity(); |
| 12556 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12557 | if (controller == null) { |
| 12558 | return; |
| 12559 | } |
| 12560 | try { |
| 12561 | controller.unregisterImsStateCallback(cb); |
| 12562 | } finally { |
| 12563 | Binder.restoreCallingIdentity(token); |
| 12564 | } |
| 12565 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12566 | |
| 12567 | /** |
| 12568 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12569 | * |
| 12570 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12571 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12572 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12573 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12574 | * If there is current registered network this value will be same as the registered cell |
| 12575 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12576 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12577 | * it will be cleared and null will be returned. |
| 12578 | * |
| 12579 | */ |
| 12580 | @Override |
| 12581 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12582 | String callingFeatureId) { |
| 12583 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12584 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12585 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12586 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12587 | .setCallingPackage(callingPackage) |
| 12588 | .setCallingFeatureId(callingFeatureId) |
| 12589 | .setCallingPid(Binder.getCallingPid()) |
| 12590 | .setCallingUid(Binder.getCallingUid()) |
| 12591 | .setMethod("getLastKnownCellIdentity") |
| 12592 | .setLogAsInfo(true) |
| 12593 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12594 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12595 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12596 | .build()); |
| 12597 | |
| 12598 | boolean hasFinePermission = |
| 12599 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12600 | if (!hasFinePermission |
| 12601 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12602 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12603 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12604 | } |
| 12605 | |
| 12606 | final long identity = Binder.clearCallingIdentity(); |
| 12607 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12608 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12609 | if (sst == null) return null; |
| 12610 | return sst.getLastKnownCellIdentity(); |
| 12611 | } finally { |
| 12612 | Binder.restoreCallingIdentity(identity); |
| 12613 | } |
| 12614 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12615 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12616 | /** |
| 12617 | * Sets the modem service class Name that Telephony will bind to. |
| 12618 | * |
| 12619 | * @param serviceName The class name of the modem service. |
| 12620 | * @return true if the operation is succeed, otherwise false. |
| 12621 | */ |
| 12622 | public boolean setModemService(String serviceName) { |
| 12623 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12624 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12626 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12627 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12628 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12629 | } |
| 12630 | |
| 12631 | /** |
| 12632 | * Return the class name of the currently bounded modem service. |
| 12633 | * |
| 12634 | * @return the class name of the modem service. |
| 12635 | */ |
| 12636 | public String getModemService() { |
| 12637 | String result; |
| 12638 | Log.d(LOG_TAG, "getModemService"); |
| 12639 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12640 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12641 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12642 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12643 | "getModemService"); |
| 12644 | result = mPhoneConfigurationManager.getModemService(); |
| 12645 | Log.d(LOG_TAG, "result = " + result); |
| 12646 | return result; |
| 12647 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12648 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12649 | /** |
| 12650 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12651 | * including carrier config, entitlement server, and config update. |
| 12652 | * |
| 12653 | * @param subId subId The subscription ID of the carrier. |
| 12654 | * |
| 12655 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12656 | * be returned. |
| 12657 | * |
| 12658 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12659 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12660 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12661 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12662 | final long identity = Binder.clearCallingIdentity(); |
| 12663 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12664 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12665 | } finally { |
| 12666 | Binder.restoreCallingIdentity(identity); |
| 12667 | } |
| 12668 | } |
| 12669 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12670 | @Override |
| 12671 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12672 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12673 | mApp.enforceCallingOrSelfPermission( |
| 12674 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12675 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12676 | |
| 12677 | final long identity = Binder.clearCallingIdentity(); |
| 12678 | try { |
| 12679 | Phone phone = getPhone(subId); |
| 12680 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12681 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12682 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12683 | phone.setVoiceServiceStateOverride(hasService); |
| 12684 | } finally { |
| 12685 | Binder.restoreCallingIdentity(identity); |
| 12686 | } |
| 12687 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12688 | |
| 12689 | /** |
| 12690 | * set removable eSIM as default eUICC. |
| 12691 | * |
| 12692 | * @hide |
| 12693 | */ |
| 12694 | @Override |
| 12695 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12696 | enforceModifyPermission(); |
| 12697 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12698 | |
| 12699 | final long identity = Binder.clearCallingIdentity(); |
| 12700 | try { |
| 12701 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12702 | } finally { |
| 12703 | Binder.restoreCallingIdentity(identity); |
| 12704 | } |
| 12705 | } |
| 12706 | |
| 12707 | /** |
| 12708 | * Returns whether the removable eSIM is default eUICC or not. |
| 12709 | * |
| 12710 | * @hide |
| 12711 | */ |
| 12712 | @Override |
| 12713 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12714 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12715 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12716 | |
| 12717 | final long identity = Binder.clearCallingIdentity(); |
| 12718 | try { |
| 12719 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12720 | } finally { |
| 12721 | Binder.restoreCallingIdentity(identity); |
| 12722 | } |
| 12723 | } |
| 12724 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12725 | /** |
| 12726 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12727 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12728 | * application currently configured for this user. |
| 12729 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12730 | * {@code null} if the functionality is not supported. |
| 12731 | * @hide |
| 12732 | */ |
| 12733 | @Override |
| 12734 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12735 | boolean updateIfNeeded) { |
| 12736 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12737 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12738 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12739 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12740 | "getDefaultRespondViaMessageApplication"); |
| 12741 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12742 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12743 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12744 | UserHandle userHandle = null; |
| 12745 | final long identity = Binder.clearCallingIdentity(); |
| 12746 | try { |
| 12747 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12748 | } finally { |
| 12749 | Binder.restoreCallingIdentity(identity); |
| 12750 | } |
| 12751 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12752 | updateIfNeeded, userHandle); |
| 12753 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12754 | |
| 12755 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12756 | * Set whether the device is able to connect with null ciphering or integrity |
| 12757 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12758 | * and all new subscriptions after this. |
| 12759 | * |
| 12760 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12761 | * @hide |
| 12762 | */ |
| 12763 | @Override |
| 12764 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12765 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12766 | enforceModifyPermission(); |
| 12767 | checkForNullCipherAndIntegritySupport(); |
| 12768 | |
| 12769 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12770 | // for listening to these preference changes and applying them immediately. |
| 12771 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12772 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12773 | editor.apply(); |
| 12774 | |
| 12775 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12776 | phone.handleNullCipherEnabledChange(); |
| 12777 | } |
| 12778 | } |
| 12779 | |
| 12780 | |
| 12781 | /** |
| 12782 | * Get whether the device is able to connect with null ciphering or integrity |
| 12783 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12784 | * the state of the radio. |
| 12785 | * |
| 12786 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12787 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12788 | * version for this feature. |
| 12789 | * @hide |
| 12790 | */ |
| 12791 | @Override |
| 12792 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12793 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12794 | enforceReadPermission(); |
| 12795 | checkForNullCipherAndIntegritySupport(); |
| 12796 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12797 | } |
| 12798 | |
| 12799 | private void checkForNullCipherAndIntegritySupport() { |
| 12800 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12801 | throw new UnsupportedOperationException( |
| 12802 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12803 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12804 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12805 | throw new UnsupportedOperationException( |
| 12806 | "Null cipher and integrity operations unsupported by modem"); |
| 12807 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12808 | } |
| 12809 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12810 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12811 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12812 | throw new UnsupportedOperationException( |
| 12813 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12814 | + "above"); |
| 12815 | } |
| 12816 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12817 | throw new UnsupportedOperationException( |
| 12818 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12819 | } |
| 12820 | } |
| 12821 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12822 | private void checkForNullCipherNotificationSupport() { |
| 12823 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12824 | throw new UnsupportedOperationException( |
| 12825 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12826 | } |
| 12827 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12828 | throw new UnsupportedOperationException( |
| 12829 | "Null cipher notification operations unsupported by modem"); |
| 12830 | } |
| 12831 | } |
| 12832 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12833 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12834 | * Get the SIM state for the slot index. |
| 12835 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12836 | * |
| 12837 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12838 | */ |
| 12839 | @Override |
| 12840 | @SimState |
| 12841 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12842 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12843 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12844 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12845 | IccCardConstants.State simState; |
| 12846 | if (slotIndex < 0) { |
| 12847 | simState = IccCardConstants.State.UNKNOWN; |
| 12848 | } else { |
| 12849 | Phone phone = null; |
| 12850 | try { |
| 12851 | phone = PhoneFactory.getPhone(slotIndex); |
| 12852 | } catch (IllegalStateException e) { |
| 12853 | // ignore |
| 12854 | } |
| 12855 | if (phone == null) { |
| 12856 | simState = IccCardConstants.State.UNKNOWN; |
| 12857 | } else { |
| 12858 | IccCard icc = phone.getIccCard(); |
| 12859 | if (icc == null) { |
| 12860 | simState = IccCardConstants.State.UNKNOWN; |
| 12861 | } else { |
| 12862 | simState = icc.getState(); |
| 12863 | } |
| 12864 | } |
| 12865 | } |
| 12866 | return simState.ordinal(); |
| 12867 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12868 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12869 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12870 | boolean enableLogcat, |
| 12871 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12872 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12873 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12874 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12875 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12876 | ecdDataBuilder |
| 12877 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12878 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12879 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12880 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12881 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12882 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12883 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12884 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12885 | Executors.newCachedThreadPool(), db, |
| 12886 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12887 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12888 | } |
| 12889 | |
| 12890 | /** |
| 12891 | * Request telephony to persist state for debugging emergency call failures. |
| 12892 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12893 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12894 | * @param enableLogcat whether to collect logcat output |
| 12895 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12896 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12897 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12898 | */ |
| 12899 | @Override |
| 12900 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12901 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12902 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12903 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 12904 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 12905 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 12906 | && Flags.enableReadDropboxPermission()) { |
| 12907 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 12908 | "persistEmergencyCallDiagnosticData"); |
| 12909 | } else { |
| 12910 | // Otherwise, enforce legacy permission. |
| 12911 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12912 | "persistEmergencyCallDiagnosticData"); |
| 12913 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12914 | final long identity = Binder.clearCallingIdentity(); |
| 12915 | try { |
| 12916 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12917 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12918 | |
| 12919 | } finally { |
| 12920 | Binder.restoreCallingIdentity(identity); |
| 12921 | } |
| 12922 | } |
| 12923 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12924 | /** |
| 12925 | * Get current cell broadcast ranges. |
| 12926 | */ |
| 12927 | @Override |
| 12928 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12929 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12930 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12931 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12932 | |
| 12933 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12934 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12935 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12936 | final long identity = Binder.clearCallingIdentity(); |
| 12937 | try { |
| 12938 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12939 | } finally { |
| 12940 | Binder.restoreCallingIdentity(identity); |
| 12941 | } |
| 12942 | } |
| 12943 | |
| 12944 | /** |
| 12945 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12946 | * |
| 12947 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12948 | */ |
| 12949 | @Override |
| 12950 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12951 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12952 | @Nullable IIntegerConsumer callback) { |
| 12953 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12954 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12955 | |
| 12956 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12957 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12958 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12959 | final long identity = Binder.clearCallingIdentity(); |
| 12960 | try { |
| 12961 | Phone phone = getPhoneFromSubId(subId); |
| 12962 | if (DBG) { |
| 12963 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12964 | } |
| 12965 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12966 | if (callback != null) { |
| 12967 | try { |
| 12968 | callback.accept(result); |
| 12969 | } catch (RemoteException e) { |
| 12970 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12971 | } |
| 12972 | } |
| 12973 | }); |
| 12974 | } finally { |
| 12975 | Binder.restoreCallingIdentity(identity); |
| 12976 | } |
| 12977 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12978 | |
| 12979 | /** |
| 12980 | * Returns whether the device supports the domain selection service. |
| 12981 | * |
| 12982 | * @return {@code true} if the device supports the domain selection service. |
| 12983 | */ |
| 12984 | @Override |
| 12985 | public boolean isDomainSelectionSupported() { |
| 12986 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12987 | "isDomainSelectionSupported"); |
| 12988 | |
| 12989 | final long identity = Binder.clearCallingIdentity(); |
| 12990 | try { |
| 12991 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12992 | } finally { |
| 12993 | Binder.restoreCallingIdentity(identity); |
| 12994 | } |
| 12995 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12996 | |
| 12997 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame^] | 12998 | * Returns whether the AOSP domain selection service is supported. |
| 12999 | * |
| 13000 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13001 | * {@code false} otherwise. |
| 13002 | */ |
| 13003 | @Override |
| 13004 | public boolean isAospDomainSelectionService() { |
| 13005 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13006 | "isAospDomainSelectionService"); |
| 13007 | |
| 13008 | final long identity = Binder.clearCallingIdentity(); |
| 13009 | try { |
| 13010 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13011 | String dssComponentName = mApp.getResources().getString( |
| 13012 | R.string.config_domain_selection_service_component_name); |
| 13013 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13014 | TelephonyDomainSelectionService.class.getName()); |
| 13015 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13016 | + ", aosp=" + componentName.flattenToString()); |
| 13017 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13018 | } |
| 13019 | } finally { |
| 13020 | Binder.restoreCallingIdentity(identity); |
| 13021 | } |
| 13022 | return false; |
| 13023 | } |
| 13024 | |
| 13025 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13026 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13027 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13028 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13029 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13030 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13031 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13032 | * {@code false} to disable. |
| 13033 | * @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] | 13034 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13035 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13036 | * |
| 13037 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13038 | */ |
| 13039 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13040 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13041 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13042 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13043 | if (enableSatellite) { |
| 13044 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13045 | @Override |
| 13046 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13047 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13048 | + ", resultData=" + resultData); |
| 13049 | boolean isAllowed = false; |
| 13050 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13051 | callback::accept); |
| 13052 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13053 | if (resultData != null |
| 13054 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13055 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13056 | } else { |
| 13057 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13058 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13059 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13060 | result.accept(resultCode); |
| 13061 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13062 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13063 | if (isAllowed) { |
| 13064 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13065 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13066 | } else { |
| 13067 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13068 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13069 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13070 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13071 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13072 | subId, resultReceiver); |
| 13073 | } else { |
| 13074 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13075 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13076 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13077 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13078 | } |
| 13079 | |
| 13080 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13081 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13082 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13083 | * @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] | 13084 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13085 | * 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] | 13086 | * |
| 13087 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13088 | */ |
| 13089 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13090 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13091 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13092 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13093 | } |
| 13094 | |
| 13095 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13096 | * Request to get whether the satellite service demo mode is enabled. |
| 13097 | * |
| 13098 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13099 | * is enabled for. |
| 13100 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13101 | * if the request is successful or an error code if the request failed. |
| 13102 | * |
| 13103 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13104 | */ |
| 13105 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13106 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13107 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13108 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13109 | } |
| 13110 | |
| 13111 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13112 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13113 | * |
| 13114 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13115 | * is enabled for. |
| 13116 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13117 | * enabled if the request is successful or an error code if the request failed. |
| 13118 | * |
| 13119 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13120 | */ |
| 13121 | @Override |
| 13122 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13123 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
| 13124 | result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null); |
| 13125 | } |
| 13126 | |
| 13127 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13128 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13129 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13130 | * @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] | 13131 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13132 | * 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] | 13133 | */ |
| 13134 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13135 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13136 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13137 | } |
| 13138 | |
| 13139 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13140 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13141 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13142 | * @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] | 13143 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13144 | * 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] | 13145 | * |
| 13146 | * @throws SecurityException if the caller doesn't have required permission. |
| 13147 | */ |
| 13148 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13149 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13150 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13151 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13152 | } |
| 13153 | |
| 13154 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13155 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13156 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13157 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13158 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13159 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13160 | * @param resultCallback The callback to get the result of the request. |
| 13161 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13162 | * |
| 13163 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13164 | */ |
| 13165 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13166 | public void startSatelliteTransmissionUpdates(int subId, |
| 13167 | @NonNull IIntegerConsumer resultCallback, |
| 13168 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13169 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13170 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13171 | } |
| 13172 | |
| 13173 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13174 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13175 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13176 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13177 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13178 | * @param resultCallback The callback to get the result of the request. |
| 13179 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13180 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13181 | * |
| 13182 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13183 | */ |
| 13184 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13185 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13186 | @NonNull IIntegerConsumer resultCallback, |
| 13187 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13188 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13189 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13190 | } |
| 13191 | |
| 13192 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13193 | * Register the subscription with a satellite provider. |
| 13194 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13195 | * |
| 13196 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13197 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13198 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13199 | * @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] | 13200 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13201 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13202 | * @return The signal transport used by the caller to cancel the provision request, |
| 13203 | * or {@code null} if the request failed. |
| 13204 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13205 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13206 | */ |
| 13207 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13208 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13209 | @NonNull String token, @NonNull byte[] provisionData, |
| 13210 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13211 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13212 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13213 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13214 | } |
| 13215 | |
| 13216 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13217 | * Unregister the device/subscription with the satellite provider. |
| 13218 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13219 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13220 | * should report as deprovisioned. |
| 13221 | * |
| 13222 | * @param subId The subId of the subscription to be deprovisioned. |
| 13223 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13224 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13225 | * |
| 13226 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13227 | */ |
| 13228 | @Override |
| 13229 | public void deprovisionSatelliteService(int subId, |
| 13230 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13231 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13232 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13233 | } |
| 13234 | |
| 13235 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13236 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13237 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13238 | * @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] | 13239 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13240 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13241 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13242 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13243 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13244 | */ |
| 13245 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13246 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13247 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13248 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13249 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13250 | } |
| 13251 | |
| 13252 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13253 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13254 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13255 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13256 | * @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] | 13257 | * @param callback The callback that was passed to |
| 13258 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13259 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13260 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13261 | */ |
| 13262 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13263 | public void unregisterForSatelliteProvisionStateChanged( |
| 13264 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13265 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13266 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13267 | } |
| 13268 | |
| 13269 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13270 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13271 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13272 | * @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] | 13273 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13274 | * satellite provider if the request is successful or an error code if the |
| 13275 | * request failed. |
| 13276 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13277 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13278 | */ |
| 13279 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13280 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13281 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13282 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13283 | } |
| 13284 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13285 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13286 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13287 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13288 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13289 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13290 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13291 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13292 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13293 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13294 | */ |
| 13295 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13296 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13297 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13298 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13299 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13300 | } |
| 13301 | |
| 13302 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13303 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13304 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13305 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13306 | * @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] | 13307 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13308 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13309 | * |
| 13310 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13311 | */ |
| 13312 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13313 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13314 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13315 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13316 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13317 | } |
| 13318 | |
| 13319 | /** |
| 13320 | * Register to receive incoming datagrams over satellite. |
| 13321 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13322 | * @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] | 13323 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13324 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13325 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13326 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13327 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13328 | */ |
| 13329 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13330 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13331 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13332 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13333 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13334 | } |
| 13335 | |
| 13336 | /** |
| 13337 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13338 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13339 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13340 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13341 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13342 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13343 | * |
| 13344 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13345 | */ |
| 13346 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13347 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13348 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13349 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13350 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13351 | } |
| 13352 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13353 | /** |
| 13354 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13355 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13356 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13357 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13358 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13359 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13360 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13361 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13362 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13363 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13364 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13365 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13366 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13367 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13368 | } |
| 13369 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13370 | /** |
| 13371 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13372 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13373 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13374 | * input to this method. Datagram received here will be passed down to modem without any |
| 13375 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13376 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13377 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13378 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13379 | * SOS_SMS or LOCATION_SHARING. |
| 13380 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13381 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13382 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13383 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13384 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13385 | * |
| 13386 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13387 | */ |
| 13388 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13389 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13390 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13391 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13392 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13393 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13394 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13395 | } |
| 13396 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13397 | /** |
| 13398 | * Request to get whether satellite communication is allowed for the current location. |
| 13399 | * |
| 13400 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13401 | * allowed for the current location for. |
| 13402 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13403 | * for the current location if the request is successful or an error code |
| 13404 | * if the request failed. |
| 13405 | * |
| 13406 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13407 | */ |
| 13408 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13409 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13410 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13411 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13412 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13413 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13414 | } |
| 13415 | |
| 13416 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13417 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13418 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13419 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13420 | * @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] | 13421 | * be visible if the request is successful or an error code if the request failed. |
| 13422 | * |
| 13423 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13424 | */ |
| 13425 | @Override |
| 13426 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13427 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13428 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13429 | } |
| 13430 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13431 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13432 | * Inform that Device is aligned to satellite for demo mode. |
| 13433 | * |
| 13434 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13435 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13436 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13437 | * |
| 13438 | * @throws SecurityException if the caller doesn't have required permission. |
| 13439 | */ |
| 13440 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13441 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13442 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13443 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13444 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13445 | } |
| 13446 | |
| 13447 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13448 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13449 | * by modem. |
| 13450 | * |
| 13451 | * @param subId The subId of the subscription to request for. |
| 13452 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13453 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13454 | * operation. |
| 13455 | * |
| 13456 | * @throws SecurityException if the caller doesn't have required permission. |
| 13457 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13458 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13459 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13460 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13461 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13462 | final long identity = Binder.clearCallingIdentity(); |
| 13463 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13464 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13465 | } finally { |
| 13466 | Binder.restoreCallingIdentity(identity); |
| 13467 | } |
| 13468 | } |
| 13469 | |
| 13470 | /** |
| 13471 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13472 | * by modem. |
| 13473 | * |
| 13474 | * @param subId The subId of the subscription to request for. |
| 13475 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13476 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13477 | * operation. |
| 13478 | * |
| 13479 | * @throws SecurityException if the caller doesn't have required permission. |
| 13480 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13481 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13482 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13483 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13484 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13485 | final long identity = Binder.clearCallingIdentity(); |
| 13486 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13487 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13488 | } finally { |
| 13489 | Binder.restoreCallingIdentity(identity); |
| 13490 | } |
| 13491 | } |
| 13492 | |
| 13493 | /** |
| 13494 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13495 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13496 | * |
| 13497 | * @param subId The subId of the subscription to request for. |
| 13498 | * |
| 13499 | * @return Integer array of reasons for disallowing satellite communication. |
| 13500 | * |
| 13501 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13502 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13503 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13504 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13505 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13506 | final long identity = Binder.clearCallingIdentity(); |
| 13507 | try { |
| 13508 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13509 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13510 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13511 | } finally { |
| 13512 | Binder.restoreCallingIdentity(identity); |
| 13513 | } |
| 13514 | } |
| 13515 | |
| 13516 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13517 | * Request to get the signal strength of the satellite connection. |
| 13518 | * |
| 13519 | * @param subId The subId of the subscription to request for. |
| 13520 | * @param result Result receiver to get the error code of the request and the current signal |
| 13521 | * strength of the satellite connection. |
| 13522 | * |
| 13523 | * @throws SecurityException if the caller doesn't have required permission. |
| 13524 | */ |
| 13525 | @Override |
| 13526 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13527 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13528 | final long identity = Binder.clearCallingIdentity(); |
| 13529 | try { |
| 13530 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13531 | } finally { |
| 13532 | Binder.restoreCallingIdentity(identity); |
| 13533 | } |
| 13534 | } |
| 13535 | |
| 13536 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13537 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13538 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13539 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13540 | * |
| 13541 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13542 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13543 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13544 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13545 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13546 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13547 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13548 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13549 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13550 | */ |
| 13551 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13552 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13553 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13554 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13555 | final long identity = Binder.clearCallingIdentity(); |
| 13556 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13557 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13558 | } finally { |
| 13559 | Binder.restoreCallingIdentity(identity); |
| 13560 | } |
| 13561 | } |
| 13562 | |
| 13563 | /** |
| 13564 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13565 | * If callback was not registered before, the request will be ignored. |
| 13566 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13567 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13568 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13569 | * @param callback The callback that was passed to |
| 13570 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13571 | * |
| 13572 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13573 | */ |
| 13574 | @Override |
| 13575 | public void unregisterForNtnSignalStrengthChanged( |
| 13576 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13577 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13578 | final long identity = Binder.clearCallingIdentity(); |
| 13579 | try { |
| 13580 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13581 | } finally { |
| 13582 | Binder.restoreCallingIdentity(identity); |
| 13583 | } |
| 13584 | } |
| 13585 | |
| 13586 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13587 | * Registers for satellite capabilities change event from the satellite service. |
| 13588 | * |
| 13589 | * @param subId The subId of the subscription to request for. |
| 13590 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13591 | * |
| 13592 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13593 | * |
| 13594 | * @throws SecurityException if the caller doesn't have required permission. |
| 13595 | */ |
| 13596 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13597 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13598 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13599 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13600 | final long identity = Binder.clearCallingIdentity(); |
| 13601 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13602 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13603 | } finally { |
| 13604 | Binder.restoreCallingIdentity(identity); |
| 13605 | } |
| 13606 | } |
| 13607 | |
| 13608 | /** |
| 13609 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13610 | * If callback was not registered before, the request will be ignored. |
| 13611 | * |
| 13612 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13613 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13614 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13615 | * |
| 13616 | * @throws SecurityException if the caller doesn't have required permission. |
| 13617 | */ |
| 13618 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13619 | public void unregisterForCapabilitiesChanged(int subId, |
| 13620 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13621 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13622 | final long identity = Binder.clearCallingIdentity(); |
| 13623 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13624 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13625 | } finally { |
| 13626 | Binder.restoreCallingIdentity(identity); |
| 13627 | } |
| 13628 | } |
| 13629 | |
| 13630 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13631 | * Registers for the satellite supported state changed. |
| 13632 | * |
| 13633 | * @param subId The subId of the subscription to register for supported state changed. |
| 13634 | * @param callback The callback to handle the satellite supported state changed event. |
| 13635 | * |
| 13636 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13637 | * |
| 13638 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13639 | */ |
| 13640 | @Override |
| 13641 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
| 13642 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13643 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
| 13644 | return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback); |
| 13645 | } |
| 13646 | |
| 13647 | /** |
| 13648 | * Unregisters for the satellite supported state changed. |
| 13649 | * If callback was not registered before, the request will be ignored. |
| 13650 | * |
| 13651 | * @param subId The subId of the subscription to unregister for supported state changed. |
| 13652 | * @param callback The callback that was passed to |
| 13653 | * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}. |
| 13654 | * |
| 13655 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13656 | */ |
| 13657 | @Override |
| 13658 | public void unregisterForSatelliteSupportedStateChanged( |
| 13659 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13660 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
| 13661 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback); |
| 13662 | } |
| 13663 | |
| 13664 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13665 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13666 | * |
| 13667 | * @param servicePackageName The package name of the satellite vendor service. |
| 13668 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13669 | * {@code false} otherwise. |
| 13670 | */ |
| 13671 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13672 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13673 | TelephonyPermissions.enforceShellOnly( |
| 13674 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13676 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13677 | "setSatelliteServicePackageName"); |
| 13678 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13679 | } |
| 13680 | |
| 13681 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13682 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13683 | * |
| 13684 | * @param servicePackageName The package name of the satellite gateway service. |
| 13685 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13686 | * {@code false} otherwise. |
| 13687 | */ |
| 13688 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13689 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13690 | TelephonyPermissions.enforceShellOnly( |
| 13691 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13692 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13693 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13694 | "setSatelliteGatewayServicePackageName"); |
| 13695 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13696 | } |
| 13697 | |
| 13698 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13699 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13700 | * |
| 13701 | * @param packageName The package name of the satellite pointing UI app. |
| 13702 | * @param className The class name of the satellite pointing UI app. |
| 13703 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13704 | * {@code false} otherwise. |
| 13705 | */ |
| 13706 | public boolean setSatellitePointingUiClassName( |
| 13707 | @Nullable String packageName, @Nullable String className) { |
| 13708 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13709 | + ", className=" + className); |
| 13710 | TelephonyPermissions.enforceShellOnly( |
| 13711 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13713 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13714 | "setSatelliteGatewayServicePackageName"); |
| 13715 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13716 | } |
| 13717 | |
| 13718 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13719 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13720 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13721 | * listening mode. |
| 13722 | * |
| 13723 | * @param timeoutMillis The timeout duration in millisecond. |
| 13724 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13725 | */ |
| 13726 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13727 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13728 | TelephonyPermissions.enforceShellOnly( |
| 13729 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13730 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13731 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13732 | "setSatelliteListeningTimeoutDuration"); |
| 13733 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13734 | } |
| 13735 | |
| 13736 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13737 | * This API can be used by only CTS to override the timeout durations used by the |
| 13738 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13739 | * |
| 13740 | * @param timeoutMillis The timeout duration in millisecond. |
| 13741 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13742 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13743 | public boolean setDatagramControllerTimeoutDuration( |
| 13744 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13745 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13746 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13747 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13748 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13750 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13751 | "setDatagramControllerTimeoutDuration"); |
| 13752 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13753 | reset, timeoutType, timeoutMillis); |
| 13754 | } |
| 13755 | |
| 13756 | /** |
| 13757 | * This API can be used by only CTS to override the timeout durations used by the |
| 13758 | * SatelliteController module. |
| 13759 | * |
| 13760 | * @param timeoutMillis The timeout duration in millisecond. |
| 13761 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13762 | */ |
| 13763 | public boolean setSatelliteControllerTimeoutDuration( |
| 13764 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13765 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13766 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13767 | TelephonyPermissions.enforceShellOnly( |
| 13768 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13770 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13771 | "setSatelliteControllerTimeoutDuration"); |
| 13772 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13773 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13774 | } |
| 13775 | |
| 13776 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13777 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13778 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13779 | * |
| 13780 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13781 | * of the following values to enable the override: |
| 13782 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13783 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13784 | * To disable the override, use -1 for handoverType. |
| 13785 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13786 | * delaySeconds after the emergency call starts. |
| 13787 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13788 | */ |
| 13789 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13790 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13791 | TelephonyPermissions.enforceShellOnly( |
| 13792 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13793 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13794 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13795 | "setEmergencyCallToSatelliteHandoverType"); |
| 13796 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13797 | handoverType, delaySeconds); |
| 13798 | } |
| 13799 | |
| 13800 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13801 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13802 | * |
| 13803 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13804 | * otherwise. |
| 13805 | * @param isProvisioned The overriding provision status. |
| 13806 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13807 | */ |
| 13808 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13809 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13810 | + ", isProvisioned=" + isProvisioned); |
| 13811 | TelephonyPermissions.enforceShellOnly( |
| 13812 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13814 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13815 | "setOemEnabledSatelliteProvisionStatus"); |
| 13816 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13817 | } |
| 13818 | |
| 13819 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13820 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13821 | * |
| 13822 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13823 | */ |
| 13824 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13825 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13826 | long locationCountryCodeTimestampNanos) { |
| 13827 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13828 | + String.join(", ", currentNetworkCountryCodes) |
| 13829 | + ", locationCountryCode=" + locationCountryCode |
| 13830 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13831 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13832 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13833 | TelephonyPermissions.enforceShellOnly( |
| 13834 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13836 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13837 | "setCachedLocationCountryCode"); |
| 13838 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13839 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13840 | locationCountryCodeTimestampNanos); |
| 13841 | } |
| 13842 | |
| 13843 | /** |
| 13844 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13845 | * access controller. |
| 13846 | * |
| 13847 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13848 | * otherwise. |
| 13849 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13850 | */ |
| 13851 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13852 | String s2CellFile, long locationFreshDurationNanos, |
| 13853 | List<String> satelliteCountryCodes) { |
| 13854 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13855 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13856 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13857 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13858 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13859 | TelephonyPermissions.enforceShellOnly( |
| 13860 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13861 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13862 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13863 | "setSatelliteAccessControlOverlayConfigs"); |
| 13864 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13865 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13866 | } |
| 13867 | |
| 13868 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13869 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13870 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13871 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13872 | * |
| 13873 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13874 | * satellite modem or not. |
| 13875 | * |
| 13876 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13877 | */ |
| 13878 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13879 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13880 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13881 | + "disabled"); |
| 13882 | return false; |
| 13883 | } |
| 13884 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13885 | TelephonyPermissions.enforceShellOnly( |
| 13886 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13888 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13889 | "setShouldSendDatagramToModemInDemoMode"); |
| 13890 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13891 | shouldSendToModemInDemoMode); |
| 13892 | } |
| 13893 | |
| 13894 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 13895 | * Sets the service defined in ComponentName to be bound. |
| 13896 | * |
| 13897 | * This should only be used for testing. |
| 13898 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 13899 | * {@code false} otherwise. |
| 13900 | */ |
| 13901 | @Override |
| 13902 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 13903 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 13904 | |
| 13905 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13906 | "setDomainSelectionServiceOverride"); |
| 13907 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13908 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 13909 | |
| 13910 | final long identity = Binder.clearCallingIdentity(); |
| 13911 | try { |
| 13912 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13913 | return DomainSelectionResolver.getInstance() |
| 13914 | .setDomainSelectionServiceOverride(componentName); |
| 13915 | } |
| 13916 | } finally { |
| 13917 | Binder.restoreCallingIdentity(identity); |
| 13918 | } |
| 13919 | return false; |
| 13920 | } |
| 13921 | |
| 13922 | /** |
| 13923 | * Clears the DomainSelectionService override. |
| 13924 | * |
| 13925 | * This should only be used for testing. |
| 13926 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 13927 | * {@code false} otherwise. |
| 13928 | */ |
| 13929 | @Override |
| 13930 | public boolean clearDomainSelectionServiceOverride() { |
| 13931 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 13932 | |
| 13933 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13934 | "clearDomainSelectionServiceOverride"); |
| 13935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13936 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 13937 | |
| 13938 | final long identity = Binder.clearCallingIdentity(); |
| 13939 | try { |
| 13940 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13941 | return DomainSelectionResolver.getInstance() |
| 13942 | .clearDomainSelectionServiceOverride(); |
| 13943 | } |
| 13944 | } finally { |
| 13945 | Binder.restoreCallingIdentity(identity); |
| 13946 | } |
| 13947 | return false; |
| 13948 | } |
| 13949 | |
| 13950 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13951 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 13952 | * |
| 13953 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 13954 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 13955 | * identifier is sent in the clear, which has privacy implications for the user. |
| 13956 | * |
| 13957 | * @param enable if notifications about disclosure events should be enabled |
| 13958 | * @throws SecurityException if the caller does not have the required privileges |
| 13959 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13960 | */ |
| 13961 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13962 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13963 | enforceModifyPermission(); |
| 13964 | checkForIdentifierDisclosureNotificationSupport(); |
| 13965 | |
| 13966 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13967 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 13968 | editor.apply(); |
| 13969 | |
| 13970 | // Each phone instance is responsible for updating its respective modem immediately |
| 13971 | // after we've made a preference change. |
| 13972 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13973 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 13974 | } |
| 13975 | } |
| 13976 | |
| 13977 | /** |
| 13978 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 13979 | * |
| 13980 | * @throws SecurityException if the caller does not have the required privileges |
| 13981 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13982 | */ |
| 13983 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13984 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13985 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 13986 | checkForIdentifierDisclosureNotificationSupport(); |
| 13987 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 13988 | } |
| 13989 | |
| 13990 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 13991 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 13992 | * are in use by the cellular modem. |
| 13993 | * |
| 13994 | * @throws IllegalStateException if the Telephony process is not currently available |
| 13995 | * @throws SecurityException if the caller does not have the required privileges |
| 13996 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 13997 | * and integrity algorithms in use |
| 13998 | * @hide |
| 13999 | */ |
| 14000 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14001 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14002 | enforceModifyPermission(); |
| 14003 | checkForNullCipherNotificationSupport(); |
| 14004 | |
| 14005 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14006 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14007 | editor.apply(); |
| 14008 | |
| 14009 | // Each phone instance is responsible for updating its respective modem immediately |
| 14010 | // after a preference change. |
| 14011 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14012 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14013 | } |
| 14014 | } |
| 14015 | |
| 14016 | /** |
| 14017 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14018 | * cellular modem. |
| 14019 | * |
| 14020 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14021 | * @throws SecurityException if the caller does not have the required privileges |
| 14022 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14023 | * and integrity algorithms in use |
| 14024 | * @hide |
| 14025 | */ |
| 14026 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14027 | public boolean isNullCipherNotificationsEnabled() { |
| 14028 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14029 | checkForNullCipherNotificationSupport(); |
| 14030 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14031 | } |
| 14032 | |
| 14033 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14034 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14035 | * |
| 14036 | * <p>This method behaves in one of the following ways: |
| 14037 | * <ul> |
| 14038 | * <li>return true : if the calling package has the appop permission {@link |
| 14039 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14040 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14041 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14042 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14043 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14044 | * </ul> |
| 14045 | */ |
| 14046 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14047 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14048 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14049 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14050 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14051 | return true; |
| 14052 | } |
| 14053 | } |
| 14054 | return false; |
| 14055 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14056 | |
| 14057 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14058 | * @return The subscription manager service instance. |
| 14059 | */ |
| 14060 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14061 | return SubscriptionManagerService.getInstance(); |
| 14062 | } |
| 14063 | |
| 14064 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14065 | * Class binds the consumer[callback] and carrierId. |
| 14066 | */ |
| 14067 | private static class CallerCallbackInfo { |
| 14068 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14069 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14070 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14071 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14072 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14073 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14074 | } |
| 14075 | |
| 14076 | public Consumer<Integer> getConsumer() { |
| 14077 | return mConsumer; |
| 14078 | } |
| 14079 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14080 | public Set<Integer> getCarrierIds() { |
| 14081 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14082 | } |
| 14083 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14084 | |
| 14085 | /* |
| 14086 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14087 | * But the context that is passed in is unused if the phone app is already alive. |
| 14088 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14089 | */ |
| 14090 | @VisibleForTesting |
| 14091 | public void setPackageManager(PackageManager packageManager) { |
| 14092 | mPackageManager = packageManager; |
| 14093 | } |
| 14094 | |
| 14095 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14096 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14097 | * But the context that is passed in is unused if the phone app is already alive. |
| 14098 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14099 | */ |
| 14100 | @VisibleForTesting |
| 14101 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14102 | mAppOps = appOps; |
| 14103 | } |
| 14104 | |
| 14105 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14106 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14107 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14108 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14109 | */ |
| 14110 | @VisibleForTesting |
| 14111 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14112 | mFeatureFlags = featureFlags; |
| 14113 | } |
| 14114 | |
| 14115 | /** |
| 14116 | * Make sure the device has required telephony feature |
| 14117 | * |
| 14118 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14119 | */ |
| 14120 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14121 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14122 | if (callingPackage == null || mPackageManager == null) { |
| 14123 | return; |
| 14124 | } |
| 14125 | |
| 14126 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14127 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
| 14128 | Binder.getCallingUserHandle())) { |
| 14129 | return; |
| 14130 | } |
| 14131 | |
| 14132 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14133 | throw new UnsupportedOperationException( |
| 14134 | methodName + " is unsupported without " + telephonyFeature); |
| 14135 | } |
| 14136 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14137 | } |