Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS; |
| 20 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 22 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 23 | import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 24 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 26 | import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; |
| 27 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED; |
| 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Sangyun Yun | 8bb6645 | 2024-11-25 15:46:10 +0000 | [diff] [blame] | 29 | import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED; |
| 30 | import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED; |
| 31 | import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 32 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 34 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 35 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 36 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 37 | 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] | 38 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 39 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 40 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 41 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 42 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 43 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 44 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 46 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 47 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 48 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 49 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 50 | import android.compat.annotation.ChangeId; |
| 51 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 52 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 53 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 54 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.content.Context; |
| 56 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 57 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 58 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 59 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.net.Uri; |
| 61 | import android.os.AsyncResult; |
| 62 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 63 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 65 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 67 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 68 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 69 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.os.Looper; |
| 71 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 72 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 73 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 74 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 75 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 76 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 77 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 78 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 79 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 80 | import android.os.SystemClock; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 81 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 83 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 84 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 85 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 86 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 87 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 88 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 89 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 90 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 91 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 92 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 93 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 94 | import android.telephony.AccessNetworkConstants; |
| 95 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 96 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 97 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 98 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 99 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 100 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 101 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 102 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 103 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 104 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 105 | import android.telephony.CellIdentityCdma; |
| 106 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 108 | import android.telephony.CellInfoGsm; |
| 109 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 110 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 111 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 112 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 113 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 114 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 115 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 116 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 117 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 118 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 119 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 120 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 121 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 122 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 124 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 125 | import android.telephony.SignalStrengthUpdateRequest; |
| 126 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 127 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 128 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 130 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 131 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 132 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 133 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 134 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 135 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 136 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 137 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 138 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 139 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 140 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 141 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 142 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 143 | import android.telephony.gba.GbaAuthRequest; |
| 144 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 145 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 146 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 147 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 148 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 149 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 154 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 155 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 156 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 157 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 158 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 159 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 160 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 164 | import android.telephony.satellite.ISatelliteDisallowedReasonsCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 165 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 166 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 167 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Daniel Banta | 9332024 | 2024-11-21 00:34:41 +0000 | [diff] [blame] | 169 | import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 170 | import android.telephony.satellite.NtnSignalStrength; |
| 171 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 173 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 174 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 175 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 176 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 177 | import android.telephony.satellite.SatelliteSubscriberInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 179 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 180 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 181 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 182 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 183 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 184 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 185 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 186 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 187 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 206 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 208 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 219 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 221 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 222 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 225 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 226 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 227 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 228 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 231 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 232 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 234 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 235 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 236 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 237 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 238 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 239 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 240 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.IccIoResult; |
| 243 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 244 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 245 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 246 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 247 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 248 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 249 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 250 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 251 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 252 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 253 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 254 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 255 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 256 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 257 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 258 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 259 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 260 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 261 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 262 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 263 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 264 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 265 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 266 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 267 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 268 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 269 | import com.android.services.telephony.TelecomAccountRegistry; |
| 270 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 271 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 272 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 273 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 274 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 275 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 276 | import java.io.IOException; |
| 277 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 278 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 280 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 281 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 282 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 283 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 284 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 285 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 286 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 287 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 288 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 289 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 290 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 291 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 292 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 293 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 294 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 295 | |
| 296 | /** |
| 297 | * Implementation of the ITelephony interface. |
| 298 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 299 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 300 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 301 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 302 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 303 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 304 | |
| 305 | // Message codes used with mMainThreadHandler |
| 306 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 307 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 308 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 309 | private static final int CMD_OPEN_CHANNEL = 9; |
| 310 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 311 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 312 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 313 | private static final int CMD_NV_READ_ITEM = 13; |
| 314 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 315 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 316 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 317 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 318 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 319 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 320 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 321 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 322 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 323 | private static final int CMD_SEND_ENVELOPE = 25; |
| 324 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 325 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 326 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 327 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 328 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 329 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 330 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 331 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 332 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 333 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 334 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 335 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 336 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 337 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 338 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 339 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 340 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 341 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 342 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 343 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 344 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 345 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 346 | private static final int CMD_SWITCH_SLOTS = 50; |
| 347 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 348 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 349 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 350 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 351 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 352 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 353 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 354 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 355 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 356 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 357 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 358 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 359 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 360 | private static final int CMD_MODEM_REBOOT = 64; |
| 361 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 362 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 363 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 364 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 365 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 366 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 367 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 368 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 369 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 370 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 371 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 372 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 373 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 374 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 375 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 376 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 377 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 378 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 379 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 380 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 381 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 382 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 383 | private static final int CMD_GET_CALL_WAITING = 87; |
| 384 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 385 | private static final int CMD_SET_CALL_WAITING = 89; |
| 386 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 387 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 388 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 389 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 390 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 391 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 392 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 393 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 394 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 395 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 396 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 397 | private static final int CMD_SET_SIM_POWER = 101; |
| 398 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 399 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 400 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 401 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 402 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 403 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 404 | 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] | 405 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 406 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 407 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 408 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 409 | private static final int CMD_ENABLE_VONR = 113; |
| 410 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 411 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 412 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 413 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 414 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 415 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 416 | // Parameters of select command. |
| 417 | private static final int SELECT_COMMAND = 0xA4; |
| 418 | private static final int SELECT_P1 = 0x04; |
| 419 | private static final int SELECT_P2 = 0; |
| 420 | private static final int SELECT_P3 = 0x10; |
| 421 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 422 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 423 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 424 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 425 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 426 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 427 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 428 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | /** The singleton instance. */ |
| 430 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 431 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 433 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 434 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 435 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 436 | private final CallManager mCM; |
| 437 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 438 | |
| 439 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 440 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 441 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 442 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 443 | private final SharedPreferences mTelephonySharedPreferences; |
| 444 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 445 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 446 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 447 | private PackageManager mPackageManager; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 448 | private final int mVendorApiLevel; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 450 | @Nullable |
| 451 | private ComponentName mTestEuiccUiComponent; |
| 452 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 453 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 454 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 455 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 456 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 457 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 458 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 459 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 460 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 461 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 462 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 463 | // String to store multi SIM allowed |
| 464 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 465 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 466 | // The AID of ISD-R. |
| 467 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 468 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 469 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 470 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 471 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 472 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 473 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 474 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 475 | 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] | 476 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 477 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 478 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 479 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 480 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 481 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 482 | */ |
| 483 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 484 | "reset_network_erase_modem_config_enabled"; |
| 485 | |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 486 | private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 487 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 488 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 489 | |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 490 | private static final int LINE1_NUMBER_MAX_LEN = 50; |
| 491 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 492 | /** |
| 493 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 494 | * one ICCID active at the same time. |
| 495 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 496 | * |
| 497 | * @hide |
| 498 | */ |
| 499 | @ChangeId |
| 500 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 501 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 502 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 503 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 504 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 505 | * operation fails. |
| 506 | */ |
| 507 | @ChangeId |
| 508 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 509 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 510 | |
| 511 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 512 | * A request object to use for transmitting data to an ICC. |
| 513 | */ |
| 514 | private static final class IccAPDUArgument { |
| 515 | public int channel, cla, command, p1, p2, p3; |
| 516 | public String data; |
| 517 | |
| 518 | public IccAPDUArgument(int channel, int cla, int command, |
| 519 | int p1, int p2, int p3, String data) { |
| 520 | this.channel = channel; |
| 521 | this.cla = cla; |
| 522 | this.command = command; |
| 523 | this.p1 = p1; |
| 524 | this.p2 = p2; |
| 525 | this.p3 = p3; |
| 526 | this.data = data; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 531 | * A request object to use for transmitting data to an ICC. |
| 532 | */ |
| 533 | private static final class ManualNetworkSelectionArgument { |
| 534 | public OperatorInfo operatorInfo; |
| 535 | public boolean persistSelection; |
| 536 | |
| 537 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 538 | this.operatorInfo = operatorInfo; |
| 539 | this.persistSelection = persistSelection; |
| 540 | } |
| 541 | } |
| 542 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 543 | private static final class PurchasePremiumCapabilityArgument { |
| 544 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 545 | public @NonNull IIntegerConsumer callback; |
| 546 | |
| 547 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 548 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 549 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 550 | this.callback = callback; |
| 551 | } |
| 552 | } |
| 553 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 554 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 556 | * request after sending. The main thread will notify the request when it is complete. |
| 557 | */ |
| 558 | private static final class MainThreadRequest { |
| 559 | /** The argument to use for the request */ |
| 560 | public Object argument; |
| 561 | /** The result of the request that is run on the main thread */ |
| 562 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 563 | // The subscriber id that this request applies to. Defaults to |
| 564 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 565 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 566 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 567 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 568 | public Phone phone; |
| 569 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 570 | public WorkSource workSource; |
| 571 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 572 | public MainThreadRequest(Object argument) { |
| 573 | this.argument = argument; |
| 574 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 575 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 576 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 577 | this.argument = argument; |
| 578 | if (phone != null) { |
| 579 | this.phone = phone; |
| 580 | } |
| 581 | this.workSource = workSource; |
| 582 | } |
| 583 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 584 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 585 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 586 | if (subId != null) { |
| 587 | this.subId = subId; |
| 588 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 589 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 590 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 593 | private static final class IncomingThirdPartyCallArgs { |
| 594 | public final ComponentName component; |
| 595 | public final String callId; |
| 596 | public final String callerDisplayName; |
| 597 | |
| 598 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 599 | String callerDisplayName) { |
| 600 | this.component = component; |
| 601 | this.callId = callId; |
| 602 | this.callerDisplayName = callerDisplayName; |
| 603 | } |
| 604 | } |
| 605 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 606 | /** |
| 607 | * A handler that processes messages on the main thread in the phone process. Since many |
| 608 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 609 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 610 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 611 | * on, which will be notified when the operation completes and will contain the result of the |
| 612 | * request. |
| 613 | * |
| 614 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 615 | * note that request.result must be set to something non-null for the calling thread to |
| 616 | * unblock. |
| 617 | */ |
| 618 | private final class MainThreadHandler extends Handler { |
| 619 | @Override |
| 620 | public void handleMessage(Message msg) { |
| 621 | MainThreadRequest request; |
| 622 | Message onCompleted; |
| 623 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 624 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 626 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 627 | |
| 628 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | case CMD_HANDLE_USSD_REQUEST: { |
| 630 | request = (MainThreadRequest) msg.obj; |
| 631 | final Phone phone = getPhoneFromRequest(request); |
| 632 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 633 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 634 | ResultReceiver wrappedCallback = ussdObject.second; |
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 | if (!isUssdApiAllowed(request.subId)) { |
| 637 | // Carrier does not support use of this API, return failure. |
| 638 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 639 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 640 | Bundle returnData = new Bundle(); |
| 641 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 642 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 643 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | request.result = true; |
| 645 | notifyRequester(request); |
| 646 | return; |
| 647 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 648 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 649 | try { |
| 650 | request.result = phone != null |
| 651 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 652 | } catch (CallStateException cse) { |
| 653 | request.result = false; |
| 654 | } |
| 655 | // Wake up the requesting thread |
| 656 | notifyRequester(request); |
| 657 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 660 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 662 | final Phone phone = getPhoneFromRequest(request); |
| 663 | request.result = phone != null ? |
| 664 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 665 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 666 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 668 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 670 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 674 | uiccPort = getUiccPortFromRequest(request); |
| 675 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 677 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 678 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 679 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 681 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 682 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 683 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 684 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 685 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 686 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 689 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | ar = (AsyncResult) msg.obj; |
| 691 | request = (MainThreadRequest) ar.userObj; |
| 692 | if (ar.exception == null && ar.result != null) { |
| 693 | request.result = ar.result; |
| 694 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 695 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | if (ar.result == null) { |
| 697 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | } else { |
| 702 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 703 | } |
| 704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | break; |
| 707 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 709 | request = (MainThreadRequest) msg.obj; |
| 710 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 711 | uiccPort = getUiccPortFromRequest(request); |
| 712 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 713 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 714 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 715 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 716 | } else { |
| 717 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 718 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 719 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 720 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 721 | iccArgument.p2, |
| 722 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 723 | } |
| 724 | break; |
| 725 | |
| 726 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 727 | ar = (AsyncResult) msg.obj; |
| 728 | request = (MainThreadRequest) ar.userObj; |
| 729 | if (ar.exception == null && ar.result != null) { |
| 730 | request.result = ar.result; |
| 731 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 732 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | if (ar.result == null) { |
| 734 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 735 | } else if (ar.exception instanceof CommandException) { |
| 736 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 737 | ar.exception); |
| 738 | } else { |
| 739 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 740 | } |
| 741 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case CMD_EXCHANGE_SIM_IO: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 748 | uiccPort = getUiccPortFromRequest(request); |
| 749 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 750 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 751 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 753 | } else { |
| 754 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 755 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 756 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 757 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 758 | iccArgument.data, onCompleted); |
| 759 | } |
| 760 | break; |
| 761 | |
| 762 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 763 | ar = (AsyncResult) msg.obj; |
| 764 | request = (MainThreadRequest) ar.userObj; |
| 765 | if (ar.exception == null && ar.result != null) { |
| 766 | request.result = ar.result; |
| 767 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 768 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 769 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 770 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 771 | break; |
| 772 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 773 | case CMD_SEND_ENVELOPE: |
| 774 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 775 | uiccPort = getUiccPortFromRequest(request); |
| 776 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 777 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 778 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 779 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 780 | } else { |
| 781 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 782 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 783 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 784 | break; |
| 785 | |
| 786 | case EVENT_SEND_ENVELOPE_DONE: |
| 787 | ar = (AsyncResult) msg.obj; |
| 788 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 789 | if (ar.exception == null && ar.result != null) { |
| 790 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 791 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 792 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 793 | if (ar.result == null) { |
| 794 | loge("sendEnvelopeWithStatus: Empty response"); |
| 795 | } else if (ar.exception instanceof CommandException) { |
| 796 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 797 | ar.exception); |
| 798 | } else { |
| 799 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 800 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 801 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 802 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 803 | break; |
| 804 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 805 | case CMD_OPEN_CHANNEL: |
| 806 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 807 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 808 | IccLogicalChannelRequest openChannelRequest = |
| 809 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 810 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 811 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 812 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 813 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 814 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 815 | } else { |
| 816 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 817 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 818 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 819 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case EVENT_OPEN_CHANNEL_DONE: |
| 823 | ar = (AsyncResult) msg.obj; |
| 824 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 825 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 826 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 827 | int[] result = (int[]) ar.result; |
| 828 | int channelId = result[0]; |
| 829 | byte[] selectResponse = null; |
| 830 | if (result.length > 1) { |
| 831 | selectResponse = new byte[result.length - 1]; |
| 832 | for (int i = 1; i < result.length; ++i) { |
| 833 | selectResponse[i - 1] = (byte) result[i]; |
| 834 | } |
| 835 | } |
| 836 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 837 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 838 | |
| 839 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 840 | if (uiccPort == null) { |
| 841 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 842 | } else { |
| 843 | IccLogicalChannelRequest channelRequest = |
| 844 | (IccLogicalChannelRequest) request.argument; |
| 845 | channelRequest.channel = channelId; |
| 846 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 847 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 848 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 849 | if (ar.result == null) { |
| 850 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 851 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 852 | if (ar.exception != null) { |
| 853 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 854 | } |
| 855 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 856 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 857 | if (ar.exception instanceof CommandException) { |
| 858 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 859 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 860 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 861 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 862 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 863 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 864 | } |
| 865 | } |
| 866 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 867 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 868 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 869 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 870 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case CMD_CLOSE_CHANNEL: |
| 874 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 875 | uiccPort = getUiccPortFromRequest(request); |
| 876 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 877 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 878 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 879 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 880 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 881 | } else { |
| 882 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 883 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 884 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 888 | ar = (AsyncResult) msg.obj; |
| 889 | request = (MainThreadRequest) ar.userObj; |
| 890 | if (ar.exception == null) { |
| 891 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 892 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 893 | if (uiccPort == null) { |
| 894 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 895 | } else { |
| 896 | final int channelId = (Integer) request.argument; |
| 897 | uiccPort.onLogicalChannelClosed(channelId); |
| 898 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 899 | } else { |
| 900 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 901 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 902 | if (ar.exception instanceof CommandException) { |
| 903 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 904 | CommandException.Error error = |
| 905 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 906 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 907 | // should only throw exceptions from the binder threads. |
| 908 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 909 | "iccCloseLogicalChannel: invalid argument "); |
| 910 | } |
| 911 | } else { |
| 912 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 913 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 914 | request.result = (exception != null) ? exception : |
| 915 | new IllegalStateException( |
| 916 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 917 | } |
| 918 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 919 | break; |
| 920 | |
| 921 | case CMD_NV_READ_ITEM: |
| 922 | request = (MainThreadRequest) msg.obj; |
| 923 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 924 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 925 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 929 | ar = (AsyncResult) msg.obj; |
| 930 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 931 | if (ar.exception == null && ar.result != null) { |
| 932 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 933 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 934 | request.result = ""; |
| 935 | if (ar.result == null) { |
| 936 | loge("nvReadItem: Empty response"); |
| 937 | } else if (ar.exception instanceof CommandException) { |
| 938 | loge("nvReadItem: CommandException: " + |
| 939 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 940 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 941 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 942 | } |
| 943 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 944 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 945 | break; |
| 946 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 947 | case CMD_NV_WRITE_ITEM: |
| 948 | request = (MainThreadRequest) msg.obj; |
| 949 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 950 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 951 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 952 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 953 | break; |
| 954 | |
| 955 | case EVENT_NV_WRITE_ITEM_DONE: |
| 956 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 957 | break; |
| 958 | |
| 959 | case CMD_NV_WRITE_CDMA_PRL: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 962 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 963 | break; |
| 964 | |
| 965 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 966 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 967 | break; |
| 968 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 969 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 970 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 971 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 972 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 973 | break; |
| 974 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 975 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 976 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 977 | break; |
| 978 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 979 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 980 | request = (MainThreadRequest) msg.obj; |
| 981 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 982 | request); |
| 983 | Phone phone = getPhoneFromRequest(request); |
| 984 | if (phone != null) { |
| 985 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 986 | } else { |
| 987 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 988 | request.result = false; |
| 989 | notifyRequester(request); |
| 990 | } |
| 991 | break; |
| 992 | } |
| 993 | |
| 994 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 995 | ar = (AsyncResult) msg.obj; |
| 996 | request = (MainThreadRequest) ar.userObj; |
| 997 | if (ar.exception == null && ar.result != null) { |
| 998 | request.result = ar.result; |
| 999 | } else { |
| 1000 | // request.result must be set to something non-null |
| 1001 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1002 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1003 | request.result = ar.result; |
| 1004 | } else { |
| 1005 | request.result = false; |
| 1006 | } |
| 1007 | if (ar.result == null) { |
| 1008 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1009 | } else if (ar.exception instanceof CommandException) { |
| 1010 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1011 | + ar.exception); |
| 1012 | } else { |
| 1013 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1014 | } |
| 1015 | } |
| 1016 | notifyRequester(request); |
| 1017 | break; |
| 1018 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1019 | case CMD_IS_VONR_ENABLED: { |
| 1020 | request = (MainThreadRequest) msg.obj; |
| 1021 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1022 | request); |
| 1023 | Phone phone = getPhoneFromRequest(request); |
| 1024 | if (phone != null) { |
| 1025 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1026 | } else { |
| 1027 | loge("isVoNrEnabled: No phone object"); |
| 1028 | request.result = false; |
| 1029 | notifyRequester(request); |
| 1030 | } |
| 1031 | break; |
| 1032 | } |
| 1033 | |
| 1034 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1035 | ar = (AsyncResult) msg.obj; |
| 1036 | request = (MainThreadRequest) ar.userObj; |
| 1037 | if (ar.exception == null && ar.result != null) { |
| 1038 | request.result = ar.result; |
| 1039 | } else { |
| 1040 | // request.result must be set to something non-null |
| 1041 | // for the calling thread to unblock |
| 1042 | if (ar.result != null) { |
| 1043 | request.result = ar.result; |
| 1044 | } else { |
| 1045 | request.result = false; |
| 1046 | } |
| 1047 | if (ar.result == null) { |
| 1048 | loge("isVoNrEnabled: Empty response"); |
| 1049 | } else if (ar.exception instanceof CommandException) { |
| 1050 | loge("isVoNrEnabled: CommandException: " |
| 1051 | + ar.exception); |
| 1052 | } else { |
| 1053 | loge("isVoNrEnabled: Unknown exception"); |
| 1054 | } |
| 1055 | } |
| 1056 | notifyRequester(request); |
| 1057 | break; |
| 1058 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1059 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1060 | request = (MainThreadRequest) msg.obj; |
| 1061 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1062 | Phone phone = getPhoneFromRequest(request); |
| 1063 | if (phone != null) { |
| 1064 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1065 | request.workSource); |
| 1066 | } else { |
| 1067 | loge("enableNrDualConnectivity: No phone object"); |
| 1068 | request.result = |
| 1069 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1070 | notifyRequester(request); |
| 1071 | } |
| 1072 | break; |
| 1073 | } |
| 1074 | |
| 1075 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1076 | ar = (AsyncResult) msg.obj; |
| 1077 | request = (MainThreadRequest) ar.userObj; |
| 1078 | if (ar.exception == null) { |
| 1079 | request.result = |
| 1080 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1081 | } else { |
| 1082 | request.result = |
| 1083 | TelephonyManager |
| 1084 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1085 | if (ar.exception instanceof CommandException) { |
| 1086 | CommandException.Error error = |
| 1087 | ((CommandException) (ar.exception)).getCommandError(); |
| 1088 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1089 | request.result = |
| 1090 | TelephonyManager |
| 1091 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1092 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1093 | request.result = |
| 1094 | TelephonyManager |
| 1095 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1096 | } |
| 1097 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1098 | + ar.exception); |
| 1099 | } else { |
| 1100 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1101 | } |
| 1102 | } |
| 1103 | notifyRequester(request); |
| 1104 | break; |
| 1105 | } |
| 1106 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1107 | case CMD_ENABLE_VONR: { |
| 1108 | request = (MainThreadRequest) msg.obj; |
| 1109 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1110 | Phone phone = getPhoneFromRequest(request); |
| 1111 | if (phone != null) { |
| 1112 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1113 | request.workSource); |
| 1114 | } else { |
| 1115 | loge("setVoNrEnabled: No phone object"); |
| 1116 | request.result = |
| 1117 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1118 | notifyRequester(request); |
| 1119 | } |
| 1120 | break; |
| 1121 | } |
| 1122 | |
| 1123 | case EVENT_ENABLE_VONR_DONE: { |
| 1124 | ar = (AsyncResult) msg.obj; |
| 1125 | request = (MainThreadRequest) ar.userObj; |
| 1126 | if (ar.exception == null) { |
| 1127 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1128 | } else { |
| 1129 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1130 | if (ar.exception instanceof CommandException) { |
| 1131 | CommandException.Error error = |
| 1132 | ((CommandException) (ar.exception)).getCommandError(); |
| 1133 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1134 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1135 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1136 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1137 | } else { |
| 1138 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1139 | } |
| 1140 | loge("setVoNrEnabled" + ": CommandException: " |
| 1141 | + ar.exception); |
| 1142 | } else { |
| 1143 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1144 | } |
| 1145 | } |
| 1146 | notifyRequester(request); |
| 1147 | break; |
| 1148 | } |
| 1149 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1150 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1151 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1152 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1153 | request); |
| 1154 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1155 | break; |
| 1156 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1157 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1158 | ar = (AsyncResult) msg.obj; |
| 1159 | request = (MainThreadRequest) ar.userObj; |
| 1160 | if (ar.exception == null && ar.result != null) { |
| 1161 | request.result = ar.result; // Integer |
| 1162 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1163 | // request.result must be set to something non-null |
| 1164 | // for the calling thread to unblock |
| 1165 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1166 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1167 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1168 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1169 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1170 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1171 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1172 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1173 | } |
| 1174 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1175 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1176 | break; |
| 1177 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1178 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1179 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1180 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1181 | request); |
| 1182 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1183 | (Pair<Integer, Long>) request.argument; |
| 1184 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1185 | reasonWithNetworkTypes.first, |
| 1186 | reasonWithNetworkTypes.second, |
| 1187 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1188 | break; |
| 1189 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1190 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1191 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1192 | break; |
| 1193 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1194 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1195 | request = (MainThreadRequest) msg.obj; |
| 1196 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1197 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1198 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1199 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1200 | break; |
| 1201 | |
| 1202 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1203 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1204 | break; |
| 1205 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1206 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1207 | request = (MainThreadRequest) msg.obj; |
| 1208 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1209 | request); |
| 1210 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1211 | break; |
| 1212 | |
| 1213 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1214 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1215 | break; |
| 1216 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1217 | case CMD_PERFORM_NETWORK_SCAN: |
| 1218 | request = (MainThreadRequest) msg.obj; |
| 1219 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1220 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1221 | break; |
| 1222 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | request = (MainThreadRequest) msg.obj; |
| 1225 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1227 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1228 | request.argument; |
| 1229 | int callForwardingReason = args.first; |
| 1230 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1232 | } |
| 1233 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1234 | ar = (AsyncResult) msg.obj; |
| 1235 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1236 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1237 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1238 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1240 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1242 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1243 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1244 | // any service for voice call. |
| 1245 | if ((callForwardInfo.serviceClass |
| 1246 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1247 | callForwardingInfo = new CallForwardingInfo( |
| 1248 | callForwardInfo.status |
| 1249 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | callForwardInfo.reason, |
| 1251 | callForwardInfo.number, |
| 1252 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | // Didn't find a call forward info for voice call. |
| 1257 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1259 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1261 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | } else { |
| 1263 | if (ar.result == null) { |
| 1264 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1265 | } |
| 1266 | if (ar.exception != null) { |
| 1267 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1268 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1269 | int errorCode = TelephonyManager |
| 1270 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | if (ar.exception instanceof CommandException) { |
| 1272 | CommandException.Error error = |
| 1273 | ((CommandException) (ar.exception)).getCommandError(); |
| 1274 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1275 | errorCode = TelephonyManager |
| 1276 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1278 | errorCode = TelephonyManager |
| 1279 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | } |
| 1281 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1286 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | request = (MainThreadRequest) msg.obj; |
| 1289 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1290 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1291 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1293 | request.argument).first; |
| 1294 | request.phone.setCallForwardingOption( |
| 1295 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1296 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1297 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1298 | callForwardingInfoToSet.getReason(), |
| 1299 | callForwardingInfoToSet.getNumber(), |
| 1300 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1301 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | ar = (AsyncResult) msg.obj; |
| 1306 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | Consumer<Integer> callback = |
| 1308 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1309 | request.argument).second; |
| 1310 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1312 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1313 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | if (ar.exception instanceof CommandException) { |
| 1315 | CommandException.Error error = |
| 1316 | ((CommandException) (ar.exception)).getCommandError(); |
| 1317 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1318 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1319 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1320 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1321 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1322 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | callback.accept(errorCode); |
| 1326 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1327 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1328 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1330 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1332 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | request = (MainThreadRequest) msg.obj; |
| 1334 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1335 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1336 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1337 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | ar = (AsyncResult) msg.obj; |
| 1341 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1343 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1344 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1345 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | // Service Class is a bit mask per 3gpp 27.007. |
| 1347 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1348 | if (callForwardResults.length > 1 |
| 1349 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1350 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1351 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1353 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1354 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1355 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | } |
| 1357 | } else { |
| 1358 | if (ar.result == null) { |
| 1359 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1360 | } |
| 1361 | if (ar.exception != null) { |
| 1362 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1363 | } |
| 1364 | if (ar.exception instanceof CommandException) { |
| 1365 | CommandException.Error error = |
| 1366 | ((CommandException) (ar.exception)).getCommandError(); |
| 1367 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1368 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1369 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1370 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1371 | callWaitingStatus = |
| 1372 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1376 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1377 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1378 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1379 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1380 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1381 | request = (MainThreadRequest) msg.obj; |
| 1382 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1383 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1384 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1385 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1386 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1387 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1388 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1389 | ar = (AsyncResult) msg.obj; |
| 1390 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1391 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1392 | Consumer<Integer> callback = |
| 1393 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1394 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1395 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1396 | if (ar.exception instanceof CommandException) { |
| 1397 | CommandException.Error error = |
| 1398 | ((CommandException) (ar.exception)).getCommandError(); |
| 1399 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1400 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1401 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1402 | callback.accept( |
| 1403 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1404 | } else { |
| 1405 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1406 | } |
| 1407 | } else { |
| 1408 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1409 | } |
| 1410 | } else { |
| 1411 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1412 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1413 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1414 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1415 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1416 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1417 | ar = (AsyncResult) msg.obj; |
| 1418 | request = (MainThreadRequest) ar.userObj; |
| 1419 | CellNetworkScanResult cellScanResult; |
| 1420 | if (ar.exception == null && ar.result != null) { |
| 1421 | cellScanResult = new CellNetworkScanResult( |
| 1422 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1423 | (List<OperatorInfo>) ar.result); |
| 1424 | } else { |
| 1425 | if (ar.result == null) { |
| 1426 | loge("getCellNetworkScanResults: Empty response"); |
| 1427 | } |
| 1428 | if (ar.exception != null) { |
| 1429 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1430 | } |
| 1431 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1432 | if (ar.exception instanceof CommandException) { |
| 1433 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1434 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1435 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1436 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1437 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1438 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1439 | } |
| 1440 | } |
| 1441 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1442 | } |
| 1443 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1444 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1448 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1449 | ManualNetworkSelectionArgument selArg = |
| 1450 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1451 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1452 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1453 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1454 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1455 | break; |
| 1456 | |
| 1457 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1458 | ar = (AsyncResult) msg.obj; |
| 1459 | request = (MainThreadRequest) ar.userObj; |
| 1460 | if (ar.exception == null) { |
| 1461 | request.result = true; |
| 1462 | } else { |
| 1463 | request.result = false; |
| 1464 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1465 | } |
| 1466 | notifyRequester(request); |
| 1467 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1468 | break; |
| 1469 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1470 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1471 | request = (MainThreadRequest) msg.obj; |
| 1472 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1473 | if (defaultPhone != null) { |
| 1474 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1475 | } else { |
| 1476 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1477 | Bundle bundle = new Bundle(); |
| 1478 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1479 | new ModemActivityInfo(0, 0, 0, |
| 1480 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1481 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1482 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1483 | break; |
| 1484 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1485 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1486 | ar = (AsyncResult) msg.obj; |
| 1487 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1488 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1489 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1490 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1491 | if (mLastModemActivityInfo == null) { |
| 1492 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1493 | mLastModemActivitySpecificInfo[0] = |
| 1494 | new ActivityStatsTechSpecificInfo( |
| 1495 | 0, |
| 1496 | 0, |
| 1497 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1498 | 0); |
| 1499 | mLastModemActivityInfo = |
| 1500 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1501 | } |
| 1502 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1503 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1504 | // Update the last modem activity info and the result of the request. |
| 1505 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1506 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1507 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1508 | } else { |
| 1509 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1510 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1511 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1512 | // We don't want to return mLastModemActivityInfo which is updated |
| 1513 | // inside mergeModemActivityInfo() |
| 1514 | ret = new ModemActivityInfo( |
| 1515 | mLastModemActivityInfo.getTimestampMillis(), |
| 1516 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1517 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1518 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1519 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1520 | } else { |
| 1521 | if (ar.result == null) { |
| 1522 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1523 | error = TelephonyManager.ModemActivityInfoException |
| 1524 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1525 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1526 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1527 | error = TelephonyManager.ModemActivityInfoException |
| 1528 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1529 | } else { |
| 1530 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1531 | error = TelephonyManager.ModemActivityInfoException |
| 1532 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1535 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1536 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1537 | bundle.putParcelable( |
| 1538 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1539 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1540 | } else { |
| 1541 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1542 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1543 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1544 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1545 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1546 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1547 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1548 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1549 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1550 | CarrierRestrictionRules argument = |
| 1551 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1552 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1553 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1554 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1555 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1556 | |
| 1557 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1558 | ar = (AsyncResult) msg.obj; |
| 1559 | request = (MainThreadRequest) ar.userObj; |
| 1560 | if (ar.exception == null && ar.result != null) { |
| 1561 | request.result = ar.result; |
| 1562 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1563 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1564 | if (ar.exception instanceof CommandException) { |
| 1565 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1566 | CommandException.Error error = |
| 1567 | ((CommandException) (ar.exception)).getCommandError(); |
| 1568 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1569 | request.result = |
| 1570 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1571 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1572 | } else { |
| 1573 | loge("setAllowedCarriers: Unknown exception"); |
| 1574 | } |
| 1575 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1576 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1577 | break; |
| 1578 | |
| 1579 | case CMD_GET_ALLOWED_CARRIERS: |
| 1580 | request = (MainThreadRequest) msg.obj; |
| 1581 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1582 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1583 | break; |
| 1584 | |
| 1585 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1586 | ar = (AsyncResult) msg.obj; |
| 1587 | request = (MainThreadRequest) ar.userObj; |
| 1588 | if (ar.exception == null && ar.result != null) { |
| 1589 | request.result = ar.result; |
| 1590 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1591 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1592 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1593 | if (ar.result == null) { |
| 1594 | loge("getAllowedCarriers: Empty response"); |
| 1595 | } else if (ar.exception instanceof CommandException) { |
| 1596 | loge("getAllowedCarriers: CommandException: " + |
| 1597 | ar.exception); |
| 1598 | } else { |
| 1599 | loge("getAllowedCarriers: Unknown exception"); |
| 1600 | } |
| 1601 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1602 | if (request.argument != null) { |
| 1603 | // This is for the implementation of carrierRestrictionStatus. |
| 1604 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1605 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1606 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1607 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1608 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1609 | CarrierRestrictionRules carrierRestrictionRules = |
| 1610 | (CarrierRestrictionRules) ar.result; |
| 1611 | int carrierId = -1; |
| 1612 | try { |
| 1613 | CarrierIdentifier carrierIdentifier = |
| 1614 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1615 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1616 | carrierIdentifier); |
| 1617 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1618 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1619 | } |
| 1620 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1621 | int restrictedStatus = |
| 1622 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1623 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1624 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1625 | lockStatus = TelephonyManager |
| 1626 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1627 | } |
| 1628 | } else { |
| 1629 | Rlog.e(LOG_TAG, |
| 1630 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1631 | } |
| 1632 | callback.accept(lockStatus); |
| 1633 | } else { |
| 1634 | // This is for the implementation of getAllowedCarriers. |
| 1635 | notifyRequester(request); |
| 1636 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1637 | break; |
| 1638 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1639 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1640 | ar = (AsyncResult) msg.obj; |
| 1641 | request = (MainThreadRequest) ar.userObj; |
| 1642 | if (ar.exception == null && ar.result != null) { |
| 1643 | request.result = ar.result; |
| 1644 | } else { |
| 1645 | request.result = new IllegalArgumentException( |
| 1646 | "Failed to retrieve Forbidden Plmns"); |
| 1647 | if (ar.result == null) { |
| 1648 | loge("getForbiddenPlmns: Empty response"); |
| 1649 | } else { |
| 1650 | loge("getForbiddenPlmns: Unknown exception"); |
| 1651 | } |
| 1652 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1653 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1654 | break; |
| 1655 | |
| 1656 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1657 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1658 | uiccPort = getUiccPortFromRequest(request); |
| 1659 | if (uiccPort == null) { |
| 1660 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1661 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1662 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1663 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1664 | break; |
| 1665 | } |
| 1666 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1667 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1668 | if (uiccApp == null) { |
| 1669 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1670 | + appType); |
| 1671 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1672 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1673 | break; |
| 1674 | } else { |
| 1675 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1676 | + " specified type -- " + appType); |
| 1677 | } |
| 1678 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1679 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1680 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1681 | break; |
| 1682 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1683 | case CMD_SWITCH_SLOTS: |
| 1684 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1685 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1686 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1687 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1688 | break; |
| 1689 | |
| 1690 | case EVENT_SWITCH_SLOTS_DONE: |
| 1691 | ar = (AsyncResult) msg.obj; |
| 1692 | request = (MainThreadRequest) ar.userObj; |
| 1693 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1694 | notifyRequester(request); |
| 1695 | break; |
| 1696 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1697 | request = (MainThreadRequest) msg.obj; |
| 1698 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1699 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1700 | break; |
| 1701 | |
| 1702 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1703 | ar = (AsyncResult) msg.obj; |
| 1704 | request = (MainThreadRequest) ar.userObj; |
| 1705 | if (ar.exception != null) { |
| 1706 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1707 | } else { |
| 1708 | int mode = ((int[]) ar.result)[0]; |
| 1709 | if (mode == 0) { |
| 1710 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1711 | } else { |
| 1712 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1713 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1714 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1715 | notifyRequester(request); |
| 1716 | break; |
| 1717 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1718 | request = (MainThreadRequest) msg.obj; |
| 1719 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1720 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1721 | break; |
| 1722 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1723 | ar = (AsyncResult) msg.obj; |
| 1724 | request = (MainThreadRequest) ar.userObj; |
| 1725 | if (ar.exception != null) { |
| 1726 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1727 | } else { |
| 1728 | request.result = ((int[]) ar.result)[0]; |
| 1729 | } |
| 1730 | notifyRequester(request); |
| 1731 | break; |
| 1732 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1733 | request = (MainThreadRequest) msg.obj; |
| 1734 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1735 | int mode = (int) request.argument; |
| 1736 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1737 | break; |
| 1738 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1739 | ar = (AsyncResult) msg.obj; |
| 1740 | request = (MainThreadRequest) ar.userObj; |
| 1741 | request.result = ar.exception == null; |
| 1742 | notifyRequester(request); |
| 1743 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1744 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1745 | request = (MainThreadRequest) msg.obj; |
| 1746 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1747 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1748 | break; |
| 1749 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1750 | ar = (AsyncResult) msg.obj; |
| 1751 | request = (MainThreadRequest) ar.userObj; |
| 1752 | if (ar.exception != null) { |
| 1753 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1754 | } else { |
| 1755 | request.result = ((int[]) ar.result)[0]; |
| 1756 | } |
| 1757 | notifyRequester(request); |
| 1758 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1759 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1760 | request = (MainThreadRequest) msg.obj; |
| 1761 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1762 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1763 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1764 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1765 | break; |
| 1766 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1767 | ar = (AsyncResult) msg.obj; |
| 1768 | request = (MainThreadRequest) ar.userObj; |
| 1769 | request.result = ar.exception == null; |
| 1770 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1771 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1772 | case CMD_GET_ALL_CELL_INFO: |
| 1773 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1774 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1775 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1776 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1777 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1778 | ar = (AsyncResult) msg.obj; |
| 1779 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1780 | // If a timeout occurs, the response will be null |
| 1781 | request.result = (ar.exception == null && ar.result != null) |
| 1782 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1783 | synchronized (request) { |
| 1784 | request.notifyAll(); |
| 1785 | } |
| 1786 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1787 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1788 | request = (MainThreadRequest) msg.obj; |
| 1789 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1790 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1791 | break; |
| 1792 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1793 | ar = (AsyncResult) msg.obj; |
| 1794 | request = (MainThreadRequest) ar.userObj; |
| 1795 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1796 | try { |
| 1797 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1798 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1799 | cb.onError( |
| 1800 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1801 | ar.exception.getClass().getName(), |
| 1802 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1803 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1804 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1805 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1806 | } else { |
| 1807 | // use the result as returned |
| 1808 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1809 | } |
| 1810 | } catch (RemoteException re) { |
| 1811 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1812 | } |
| 1813 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1814 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1815 | request = (MainThreadRequest) msg.obj; |
| 1816 | WorkSource ws = (WorkSource) request.argument; |
| 1817 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1818 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1819 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1820 | } |
| 1821 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1822 | ar = (AsyncResult) msg.obj; |
| 1823 | request = (MainThreadRequest) ar.userObj; |
| 1824 | if (ar.exception == null) { |
| 1825 | request.result = ar.result; |
| 1826 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1827 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1828 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1829 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | synchronized (request) { |
| 1833 | request.notifyAll(); |
| 1834 | } |
| 1835 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1836 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1837 | case CMD_MODEM_REBOOT: |
| 1838 | request = (MainThreadRequest) msg.obj; |
| 1839 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1840 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1841 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1842 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1843 | handleNullReturnEvent(msg, "rebootModem"); |
| 1844 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1845 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1846 | request = (MainThreadRequest) msg.obj; |
| 1847 | boolean enable = (boolean) request.argument; |
| 1848 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1849 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1850 | PhoneConfigurationManager.getInstance() |
| 1851 | .enablePhone(request.phone, enable, onCompleted); |
| 1852 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1853 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1854 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1855 | ar = (AsyncResult) msg.obj; |
| 1856 | request = (MainThreadRequest) ar.userObj; |
| 1857 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1858 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1859 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1860 | if ((boolean) request.result) { |
| 1861 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1862 | updateModemStateMetrics(); |
| 1863 | } else { |
| 1864 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1865 | + ar.exception); |
| 1866 | } |
| 1867 | notifyRequester(request); |
| 1868 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1869 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1870 | case CMD_GET_MODEM_STATUS: |
| 1871 | request = (MainThreadRequest) msg.obj; |
| 1872 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1873 | PhoneConfigurationManager.getInstance() |
| 1874 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1875 | break; |
| 1876 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1877 | ar = (AsyncResult) msg.obj; |
| 1878 | request = (MainThreadRequest) ar.userObj; |
| 1879 | int id = request.phone.getPhoneId(); |
| 1880 | if (ar.exception == null && ar.result != null) { |
| 1881 | request.result = ar.result; |
| 1882 | //update the cache as modem status has changed |
| 1883 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1884 | (boolean) request.result); |
| 1885 | } else { |
| 1886 | // Return true if modem status cannot be retrieved. For most cases, |
| 1887 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1888 | // and disable modem are not supported. Modem is always on. |
| 1889 | // TODO: this should be fixed in R to support a third |
| 1890 | // status UNKNOWN b/131631629 |
| 1891 | request.result = true; |
| 1892 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1893 | + ar.exception); |
| 1894 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1895 | notifyRequester(request); |
| 1896 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1897 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1898 | request = (MainThreadRequest) msg.obj; |
| 1899 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1900 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1901 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1902 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1903 | break; |
| 1904 | } |
| 1905 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1906 | ar = (AsyncResult) msg.obj; |
| 1907 | request = (MainThreadRequest) ar.userObj; |
| 1908 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1909 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1910 | args.second.accept(ar.exception == null); |
| 1911 | notifyRequester(request); |
| 1912 | break; |
| 1913 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1914 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1915 | request = (MainThreadRequest) msg.obj; |
| 1916 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1917 | Phone phone = getPhoneFromRequest(request); |
| 1918 | if (phone != null) { |
| 1919 | phone.getSystemSelectionChannels(onCompleted); |
| 1920 | } else { |
| 1921 | loge("getSystemSelectionChannels: No phone object"); |
| 1922 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1923 | notifyRequester(request); |
| 1924 | } |
| 1925 | break; |
| 1926 | } |
| 1927 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1928 | ar = (AsyncResult) msg.obj; |
| 1929 | request = (MainThreadRequest) ar.userObj; |
| 1930 | if (ar.exception == null && ar.result != null) { |
| 1931 | request.result = ar.result; |
| 1932 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1933 | request.result = new IllegalStateException( |
| 1934 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1935 | if (ar.result == null) { |
| 1936 | loge("getSystemSelectionChannels: Empty response"); |
| 1937 | } else { |
| 1938 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1939 | } |
| 1940 | } |
| 1941 | notifyRequester(request); |
| 1942 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1943 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1944 | ar = (AsyncResult) msg.obj; |
| 1945 | request = (MainThreadRequest) ar.userObj; |
| 1946 | if (ar.exception == null && ar.result != null) { |
| 1947 | request.result = ar.result; |
| 1948 | } else { |
| 1949 | request.result = -1; |
| 1950 | loge("Failed to set Forbidden Plmns"); |
| 1951 | if (ar.result == null) { |
| 1952 | loge("setForbidenPlmns: Empty response"); |
| 1953 | } else if (ar.exception != null) { |
| 1954 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1955 | request.result = -1; |
| 1956 | } else { |
| 1957 | loge("setForbiddenPlmns: Unknown exception"); |
| 1958 | } |
| 1959 | } |
| 1960 | notifyRequester(request); |
| 1961 | break; |
| 1962 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1963 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1964 | uiccPort = getUiccPortFromRequest(request); |
| 1965 | if (uiccPort == null) { |
| 1966 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1967 | request.result = -1; |
| 1968 | notifyRequester(request); |
| 1969 | break; |
| 1970 | } |
| 1971 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1972 | (Pair<Integer, List<String>>) request.argument; |
| 1973 | appType = setFplmnsArgs.first; |
| 1974 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1975 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1976 | if (uiccApp == null) { |
| 1977 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1978 | request.result = -1; |
| 1979 | loge("Failed to get UICC App"); |
| 1980 | notifyRequester(request); |
| 1981 | } else { |
| 1982 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1983 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1984 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1985 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1986 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1987 | case CMD_ERASE_MODEM_CONFIG: |
| 1988 | request = (MainThreadRequest) msg.obj; |
| 1989 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1990 | defaultPhone.eraseModemConfig(onCompleted); |
| 1991 | break; |
| 1992 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1993 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1994 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1995 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1996 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1997 | request = (MainThreadRequest) msg.obj; |
| 1998 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1999 | notifyRequester(request); |
| 2000 | break; |
| 2001 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2002 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 2003 | request = (MainThreadRequest) msg.obj; |
| 2004 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2005 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2006 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2007 | changed.first, changed.second, onCompleted); |
| 2008 | break; |
| 2009 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2010 | ar = (AsyncResult) msg.obj; |
| 2011 | request = (MainThreadRequest) ar.userObj; |
| 2012 | if (ar.exception == null) { |
| 2013 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2014 | // If the operation is successful, update the PIN storage |
| 2015 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2016 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2017 | UiccController.getInstance().getPinStorage() |
| 2018 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2019 | } else { |
| 2020 | request.result = msg.arg1; |
| 2021 | } |
| 2022 | notifyRequester(request); |
| 2023 | break; |
| 2024 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2025 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2026 | request = (MainThreadRequest) msg.obj; |
| 2027 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2028 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2029 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2030 | enabled.first, enabled.second, onCompleted); |
| 2031 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2032 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2033 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2034 | ar = (AsyncResult) msg.obj; |
| 2035 | request = (MainThreadRequest) ar.userObj; |
| 2036 | if (ar.exception == null) { |
| 2037 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2038 | // If the operation is successful, update the PIN storage |
| 2039 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2040 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2041 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2042 | UiccController.getInstance().getPinStorage() |
| 2043 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2044 | } else { |
| 2045 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2046 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2047 | } else { |
| 2048 | request.result = msg.arg1; |
| 2049 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2050 | |
| 2051 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2052 | notifyRequester(request); |
| 2053 | break; |
| 2054 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2055 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2056 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2057 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2058 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2059 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2060 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2061 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2062 | |
| 2063 | case CMD_SET_DATA_THROTTLING: { |
| 2064 | request = (MainThreadRequest) msg.obj; |
| 2065 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2066 | DataThrottlingRequest dataThrottlingRequest = |
| 2067 | (DataThrottlingRequest) request.argument; |
| 2068 | Phone phone = getPhoneFromRequest(request); |
| 2069 | if (phone != null) { |
| 2070 | phone.setDataThrottling(onCompleted, |
| 2071 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2072 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2073 | } else { |
| 2074 | loge("setDataThrottling: No phone object"); |
| 2075 | request.result = |
| 2076 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2077 | notifyRequester(request); |
| 2078 | } |
| 2079 | |
| 2080 | break; |
| 2081 | } |
| 2082 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2083 | ar = (AsyncResult) msg.obj; |
| 2084 | request = (MainThreadRequest) ar.userObj; |
| 2085 | |
| 2086 | if (ar.exception == null) { |
| 2087 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2088 | } else if (ar.exception instanceof CommandException) { |
| 2089 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2090 | CommandException.Error error = |
| 2091 | ((CommandException) (ar.exception)).getCommandError(); |
| 2092 | |
| 2093 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2094 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2095 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2096 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2097 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2098 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2099 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2100 | } else { |
| 2101 | request.result = |
| 2102 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2103 | } |
| 2104 | } else { |
| 2105 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2106 | } |
| 2107 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2108 | notifyRequester(request); |
| 2109 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2110 | |
| 2111 | case CMD_SET_SIM_POWER: { |
| 2112 | request = (MainThreadRequest) msg.obj; |
| 2113 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2114 | request = (MainThreadRequest) msg.obj; |
| 2115 | int stateToSet = |
| 2116 | ((Pair<Integer, IIntegerConsumer>) |
| 2117 | request.argument).first; |
| 2118 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2119 | break; |
| 2120 | } |
| 2121 | case EVENT_SET_SIM_POWER_DONE: { |
| 2122 | ar = (AsyncResult) msg.obj; |
| 2123 | request = (MainThreadRequest) ar.userObj; |
| 2124 | IIntegerConsumer callback = |
| 2125 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2126 | if (ar.exception != null) { |
| 2127 | loge("setSimPower exception: " + ar.exception); |
| 2128 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2129 | .RESULT_ERROR_UNKNOWN; |
| 2130 | if (ar.exception instanceof CommandException) { |
| 2131 | CommandException.Error error = |
| 2132 | ((CommandException) (ar.exception)).getCommandError(); |
| 2133 | if (error == CommandException.Error.SIM_ERR) { |
| 2134 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2135 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2136 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2137 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2138 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2139 | } else { |
| 2140 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2141 | } |
| 2142 | } |
| 2143 | try { |
| 2144 | callback.accept(errorCode); |
| 2145 | } catch (RemoteException e) { |
| 2146 | // Ignore if the remote process is no longer available to call back. |
| 2147 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2148 | } |
| 2149 | } else { |
| 2150 | try { |
| 2151 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2152 | } catch (RemoteException e) { |
| 2153 | // Ignore if the remote process is no longer available to call back. |
| 2154 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2155 | } |
| 2156 | } |
| 2157 | break; |
| 2158 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2159 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2160 | request = (MainThreadRequest) msg.obj; |
| 2161 | |
| 2162 | final Phone phone = getPhoneFromRequest(request); |
| 2163 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2164 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2165 | notifyRequester(request); |
| 2166 | break; |
| 2167 | } |
| 2168 | |
| 2169 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2170 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2171 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2172 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2173 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2174 | request.subId, pair.first /*callingUid*/, |
| 2175 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2176 | break; |
| 2177 | } |
| 2178 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2179 | ar = (AsyncResult) msg.obj; |
| 2180 | request = (MainThreadRequest) ar.userObj; |
| 2181 | // request.result will be the exception of ar if present, true otherwise. |
| 2182 | // Be cautious not to leave result null which will wait() forever |
| 2183 | request.result = ar.exception != null ? ar.exception : true; |
| 2184 | notifyRequester(request); |
| 2185 | break; |
| 2186 | } |
| 2187 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2188 | request = (MainThreadRequest) msg.obj; |
| 2189 | |
| 2190 | Phone phone = getPhoneFromRequest(request); |
| 2191 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2192 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2193 | notifyRequester(request); |
| 2194 | break; |
| 2195 | } |
| 2196 | |
| 2197 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2198 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2199 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2200 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2201 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2202 | request.subId, pair.first /*callingUid*/, |
| 2203 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2204 | break; |
| 2205 | } |
| 2206 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2207 | ar = (AsyncResult) msg.obj; |
| 2208 | request = (MainThreadRequest) ar.userObj; |
| 2209 | request.result = ar.exception != null ? ar.exception : true; |
| 2210 | notifyRequester(request); |
| 2211 | break; |
| 2212 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2213 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2214 | case CMD_GET_SLICING_CONFIG: { |
| 2215 | request = (MainThreadRequest) msg.obj; |
| 2216 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2217 | request.phone.getSlicingConfig(onCompleted); |
| 2218 | break; |
| 2219 | } |
| 2220 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2221 | ar = (AsyncResult) msg.obj; |
| 2222 | request = (MainThreadRequest) ar.userObj; |
| 2223 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2224 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2225 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2226 | Bundle bundle = new Bundle(); |
| 2227 | int resultCode = 0; |
| 2228 | if (ar.exception != null) { |
| 2229 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2230 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2231 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2232 | } else if (ar.result == null) { |
| 2233 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2234 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2235 | } else { |
| 2236 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2237 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2238 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2242 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2243 | } |
| 2244 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2245 | result.send(resultCode, bundle); |
| 2246 | notifyRequester(request); |
| 2247 | break; |
| 2248 | } |
| 2249 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2250 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2251 | request = (MainThreadRequest) msg.obj; |
| 2252 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2253 | PurchasePremiumCapabilityArgument arg = |
| 2254 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2255 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2256 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2257 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2258 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2259 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2260 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2261 | ar = (AsyncResult) msg.obj; |
| 2262 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2263 | PurchasePremiumCapabilityArgument arg = |
| 2264 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2265 | try { |
| 2266 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2267 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2268 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2269 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2270 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2271 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2272 | } catch (RemoteException e) { |
| 2273 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2274 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2275 | + " failed: " + e; |
| 2276 | if (DBG) log(logStr); |
| 2277 | AnomalyReporter.reportAnomaly( |
| 2278 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2279 | } |
| 2280 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2281 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2282 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2283 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2284 | request = (MainThreadRequest) msg.obj; |
| 2285 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2286 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2287 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2288 | notifyRequester(request); |
| 2289 | break; |
| 2290 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | default: |
| 2292 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2293 | break; |
| 2294 | } |
| 2295 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2296 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2297 | private void notifyRequester(MainThreadRequest request) { |
| 2298 | synchronized (request) { |
| 2299 | request.notifyAll(); |
| 2300 | } |
| 2301 | } |
| 2302 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2303 | private void handleNullReturnEvent(Message msg, String command) { |
| 2304 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2305 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2306 | if (ar.exception == null) { |
| 2307 | request.result = true; |
| 2308 | } else { |
| 2309 | request.result = false; |
| 2310 | if (ar.exception instanceof CommandException) { |
| 2311 | loge(command + ": CommandException: " + ar.exception); |
| 2312 | } else { |
| 2313 | loge(command + ": Unknown exception"); |
| 2314 | } |
| 2315 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2316 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2317 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Posts the specified command to be executed on the main thread, |
| 2322 | * waits for the request to complete, and returns the result. |
| 2323 | * @see #sendRequestAsync |
| 2324 | */ |
| 2325 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2326 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2327 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * Posts the specified command to be executed on the main thread, |
| 2332 | * waits for the request to complete, and returns the result. |
| 2333 | * @see #sendRequestAsync |
| 2334 | */ |
| 2335 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2336 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2337 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * Posts the specified command to be executed on the main thread, |
| 2342 | * waits for the request to complete, and returns the result. |
| 2343 | * @see #sendRequestAsync |
| 2344 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2345 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2346 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2347 | } |
| 2348 | |
| 2349 | /** |
| 2350 | * Posts the specified command to be executed on the main thread, |
| 2351 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2352 | * if not timeout or null otherwise. |
| 2353 | * @see #sendRequestAsync |
| 2354 | */ |
| 2355 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2356 | long timeoutInMs) { |
| 2357 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | /** |
| 2361 | * Posts the specified command to be executed on the main thread, |
| 2362 | * waits for the request to complete, and returns the result. |
| 2363 | * @see #sendRequestAsync |
| 2364 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2365 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2366 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | /** |
| 2370 | * Posts the specified command to be executed on the main thread, |
| 2371 | * waits for the request to complete, and returns the result. |
| 2372 | * @see #sendRequestAsync |
| 2373 | */ |
| 2374 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2375 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2376 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2380 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2381 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2382 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2383 | * @see #sendRequestAsync |
| 2384 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2385 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2386 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2388 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2389 | } |
| 2390 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2391 | MainThreadRequest request = null; |
| 2392 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2393 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2394 | } else if (phone != null) { |
| 2395 | request = new MainThreadRequest(argument, phone, workSource); |
| 2396 | } else { |
| 2397 | request = new MainThreadRequest(argument, subId, workSource); |
| 2398 | } |
| 2399 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2401 | msg.sendToTarget(); |
| 2402 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2403 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2405 | if (timeoutInMs >= 0) { |
| 2406 | // Wait for at least timeoutInMs before returning null request result |
| 2407 | long now = SystemClock.elapsedRealtime(); |
| 2408 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2409 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2410 | try { |
| 2411 | request.wait(deadline - now); |
| 2412 | } catch (InterruptedException e) { |
| 2413 | // Do nothing, go back and check if request is completed or timeout |
| 2414 | } finally { |
| 2415 | now = SystemClock.elapsedRealtime(); |
| 2416 | } |
| 2417 | } |
| 2418 | } else { |
| 2419 | // Wait for the request to complete |
| 2420 | while (request.result == null) { |
| 2421 | try { |
| 2422 | request.wait(); |
| 2423 | } catch (InterruptedException e) { |
| 2424 | // Do nothing, go back and wait until the request is complete |
| 2425 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2429 | if (request.result == null) { |
| 2430 | Log.wtf(LOG_TAG, |
| 2431 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2432 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2433 | return request.result; |
| 2434 | } |
| 2435 | |
| 2436 | /** |
| 2437 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2438 | * Posts the specified command to be executed on the main thread, and |
| 2439 | * returns immediately. |
| 2440 | * @see #sendRequest |
| 2441 | */ |
| 2442 | private void sendRequestAsync(int command) { |
| 2443 | mMainThreadHandler.sendEmptyMessage(command); |
| 2444 | } |
| 2445 | |
| 2446 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2447 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2448 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2449 | */ |
| 2450 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2451 | sendRequestAsync(command, argument, null, null); |
| 2452 | } |
| 2453 | |
| 2454 | /** |
| 2455 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2456 | * @see {@link #sendRequest(int,Object)} |
| 2457 | */ |
| 2458 | private void sendRequestAsync( |
| 2459 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2460 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2461 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2462 | msg.sendToTarget(); |
| 2463 | } |
| 2464 | |
| 2465 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2467 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2468 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2469 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | synchronized (PhoneInterfaceManager.class) { |
| 2471 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2472 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2473 | } else { |
| 2474 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2475 | } |
| 2476 | return sInstance; |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2481 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2482 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2483 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2484 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2486 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2487 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2488 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2490 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2491 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2492 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2493 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2494 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2495 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2496 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2497 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2498 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2499 | mVendorApiLevel = SystemProperties.getInt( |
| 2500 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2501 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2502 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2503 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2504 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2505 | |
| 2506 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2507 | // entitlementStatus for satellite service. |
| 2508 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2511 | @VisibleForTesting |
| 2512 | public SharedPreferences getSharedPreferences() { |
| 2513 | return mTelephonySharedPreferences; |
| 2514 | } |
| 2515 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2516 | /** |
| 2517 | * Get the default phone for this device. |
| 2518 | */ |
| 2519 | @VisibleForTesting |
| 2520 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2521 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2522 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2523 | } |
| 2524 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | private void publish() { |
| 2526 | if (DBG) log("publish: " + this); |
| 2527 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2528 | TelephonyFrameworkInitializer |
| 2529 | .getTelephonyServiceManager() |
| 2530 | .getTelephonyServiceRegisterer() |
| 2531 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2534 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2535 | if (request.phone != null) { |
| 2536 | return request.phone; |
| 2537 | } else { |
| 2538 | return getPhoneFromSubId(request.subId); |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | private Phone getPhoneFromSubId(int subId) { |
| 2543 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2544 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2545 | } |
| 2546 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2547 | /** |
| 2548 | * Get phone object associated with a subscription. |
| 2549 | * Return default phone if phone object associated with subscription is null |
| 2550 | * @param subId - subscriptionId |
| 2551 | * @return phone object associated with a subscription or default phone if null. |
| 2552 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2553 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2554 | Phone phone = getPhoneFromSubId(subId); |
| 2555 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2556 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2557 | phone = getDefaultPhone(); |
| 2558 | } |
| 2559 | return phone; |
| 2560 | } |
| 2561 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2562 | @Nullable |
| 2563 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2564 | Phone phone = getPhoneFromRequest(request); |
| 2565 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2566 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2567 | } |
| 2568 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2569 | /** |
| 2570 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2571 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2572 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2573 | * @return The Phone associated the sub Id |
| 2574 | */ |
| 2575 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2576 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2577 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2578 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2579 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2580 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2581 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2582 | } |
| 2583 | |
| 2584 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2585 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2586 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2589 | private boolean isImsAvailableOnDevice() { |
| 2590 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2591 | if (pm == null) { |
| 2592 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2593 | // so do not throw error and allow. |
| 2594 | return true; |
| 2595 | } |
| 2596 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2597 | } |
| 2598 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2600 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2601 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2602 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2603 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2606 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2607 | if (DBG) log("dial: " + number); |
| 2608 | // No permission check needed here: This is just a wrapper around the |
| 2609 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2610 | // the UI before it does anything. |
| 2611 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
| 2614 | String url = createTelUrl(number); |
| 2615 | if (url == null) { |
| 2616 | return; |
| 2617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2620 | PhoneConstants.State state = mCM.getState(subId); |
| 2621 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2622 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2623 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2624 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | } |
| 2626 | } finally { |
| 2627 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2632 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2633 | } |
| 2634 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2635 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2636 | if (DBG) log("call: " + number); |
| 2637 | |
| 2638 | // This is just a wrapper around the ACTION_CALL intent, but we still |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2639 | // need to do a permission check since we're calling startActivityAsUser() |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2640 | // from the context of the phone app. |
| 2641 | enforceCallPermission(); |
| 2642 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2643 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2644 | != AppOpsManager.MODE_ALLOWED) { |
| 2645 | return; |
| 2646 | } |
| 2647 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2648 | enforceTelephonyFeatureWithException(callingPackage, |
| 2649 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2650 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | String url = createTelUrl(number); |
| 2654 | if (url == null) { |
| 2655 | return; |
| 2656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2658 | boolean isValid = false; |
| 2659 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2660 | if (slist != null) { |
| 2661 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2662 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2663 | isValid = true; |
| 2664 | break; |
| 2665 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2666 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2667 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | if (!isValid) { |
| 2669 | return; |
| 2670 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2671 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2673 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2674 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2675 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | } finally { |
| 2677 | Binder.restoreCallingIdentity(identity); |
| 2678 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2681 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2682 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2683 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2684 | } |
| 2685 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2686 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2687 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2688 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2689 | } |
| 2690 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2691 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2692 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2694 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2695 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2696 | "supplyPinReportResultForSubscriber"); |
| 2697 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2698 | final long identity = Binder.clearCallingIdentity(); |
| 2699 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2700 | Phone phone = getPhone(subId); |
| 2701 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | checkSimPin.start(); |
| 2703 | return checkSimPin.unlockSim(null, pin); |
| 2704 | } finally { |
| 2705 | Binder.restoreCallingIdentity(identity); |
| 2706 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2709 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2710 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2711 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2712 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2713 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2714 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | final long identity = Binder.clearCallingIdentity(); |
| 2716 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2717 | Phone phone = getPhone(subId); |
| 2718 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | checkSimPuk.start(); |
| 2720 | return checkSimPuk.unlockSim(puk, pin); |
| 2721 | } finally { |
| 2722 | Binder.restoreCallingIdentity(identity); |
| 2723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2727 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2728 | * a synchronous one. |
| 2729 | */ |
| 2730 | private static class UnlockSim extends Thread { |
| 2731 | |
| 2732 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2733 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | |
| 2735 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2736 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2737 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | |
| 2739 | // For replies from SimCard interface |
| 2740 | private Handler mHandler; |
| 2741 | |
| 2742 | // For async handler to identify request type |
| 2743 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2744 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2745 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2746 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2747 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2748 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2749 | UnlockSim(int phoneId, IccCard simCard) { |
| 2750 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2751 | mSimCard = simCard; |
| 2752 | } |
| 2753 | |
| 2754 | @Override |
| 2755 | public void run() { |
| 2756 | Looper.prepare(); |
| 2757 | synchronized (UnlockSim.this) { |
| 2758 | mHandler = new Handler() { |
| 2759 | @Override |
| 2760 | public void handleMessage(Message msg) { |
| 2761 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2762 | switch (msg.what) { |
| 2763 | case SUPPLY_PIN_COMPLETE: |
| 2764 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2765 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2766 | mRetryCount = msg.arg1; |
| 2767 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2768 | CommandException.Error error = null; |
| 2769 | if (ar.exception instanceof CommandException) { |
| 2770 | error = ((CommandException) (ar.exception)) |
| 2771 | .getCommandError(); |
| 2772 | } |
| 2773 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2774 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2775 | } else if (error == CommandException.Error.ABORTED) { |
| 2776 | /* When UiccCardApp dispose, handle message and return |
| 2777 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2778 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2779 | } else { |
| 2780 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2781 | } |
| 2782 | } else { |
| 2783 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2785 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2786 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | UnlockSim.this.notifyAll(); |
| 2788 | } |
| 2789 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2790 | case SUPPLY_PIN_DELAYED: |
| 2791 | if(!mDone) { |
| 2792 | String logStr = "Delay in receiving SIM PIN response "; |
| 2793 | if (DBG) log(logStr); |
| 2794 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2795 | } |
| 2796 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2797 | } |
| 2798 | } |
| 2799 | }; |
| 2800 | UnlockSim.this.notifyAll(); |
| 2801 | } |
| 2802 | Looper.loop(); |
| 2803 | } |
| 2804 | |
| 2805 | /* |
| 2806 | * Use PIN or PUK to unlock SIM card |
| 2807 | * |
| 2808 | * If PUK is null, unlock SIM card with PIN |
| 2809 | * |
| 2810 | * 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] | 2811 | * |
| 2812 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2813 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2814 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2815 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2816 | |
| 2817 | while (mHandler == null) { |
| 2818 | try { |
| 2819 | wait(); |
| 2820 | } catch (InterruptedException e) { |
| 2821 | Thread.currentThread().interrupt(); |
| 2822 | } |
| 2823 | } |
| 2824 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2825 | |
| 2826 | if (puk == null) { |
| 2827 | mSimCard.supplyPin(pin, callback); |
| 2828 | } else { |
| 2829 | mSimCard.supplyPuk(puk, pin, callback); |
| 2830 | } |
| 2831 | |
| 2832 | while (!mDone) { |
| 2833 | try { |
| 2834 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2835 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2836 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2837 | wait(); |
| 2838 | } catch (InterruptedException e) { |
| 2839 | // Restore the interrupted status |
| 2840 | Thread.currentThread().interrupt(); |
| 2841 | } |
| 2842 | } |
| 2843 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2844 | int[] resultArray = new int[2]; |
| 2845 | resultArray[0] = mResult; |
| 2846 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2847 | |
| 2848 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2849 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2850 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2851 | // This instance is no longer reused, so quit its thread's looper. |
| 2852 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2853 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2854 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | } |
| 2856 | } |
| 2857 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2858 | /** |
| 2859 | * This method has been removed due to privacy and stability concerns. |
| 2860 | */ |
| 2861 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2862 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2863 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2864 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2867 | @Override |
| 2868 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2869 | mApp.getSystemService(AppOpsManager.class) |
| 2870 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2871 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2872 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2873 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2874 | // Callers targeting S have no business invoking this method. |
| 2875 | return; |
| 2876 | } |
| 2877 | |
| 2878 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2879 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2880 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2881 | .setCallingPackage(callingPackage) |
| 2882 | .setCallingFeatureId(null) |
| 2883 | .setCallingPid(Binder.getCallingPid()) |
| 2884 | .setCallingUid(Binder.getCallingUid()) |
| 2885 | .setMethod("updateServiceLocation") |
| 2886 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2887 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2888 | .build()); |
| 2889 | // Apps that lack location permission have no business calling this method; |
| 2890 | // however, because no permission was declared in the public API, denials must |
| 2891 | // all be "soft". |
| 2892 | switch (locationResult) { |
| 2893 | case DENIED_HARD: /* fall through */ |
| 2894 | case DENIED_SOFT: |
| 2895 | return; |
| 2896 | } |
| 2897 | |
| 2898 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2899 | final long identity = Binder.clearCallingIdentity(); |
| 2900 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2901 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2902 | } finally { |
| 2903 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2904 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2907 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2908 | @Override |
| 2909 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2910 | return isRadioOnWithFeature(callingPackage, null); |
| 2911 | } |
| 2912 | |
| 2913 | |
| 2914 | @Override |
| 2915 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2916 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2917 | callingFeatureId); |
| 2918 | } |
| 2919 | |
| 2920 | @Deprecated |
| 2921 | @Override |
| 2922 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2923 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2926 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2927 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2928 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2929 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2930 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2931 | return false; |
| 2932 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2933 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2934 | enforceTelephonyFeatureWithException(callingPackage, |
| 2935 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2936 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2937 | final long identity = Binder.clearCallingIdentity(); |
| 2938 | try { |
| 2939 | return isRadioOnForSubscriber(subId); |
| 2940 | } finally { |
| 2941 | Binder.restoreCallingIdentity(identity); |
| 2942 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2946 | final long identity = Binder.clearCallingIdentity(); |
| 2947 | try { |
| 2948 | final Phone phone = getPhone(subId); |
| 2949 | if (phone != null) { |
| 2950 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2951 | } else { |
| 2952 | return false; |
| 2953 | } |
| 2954 | } finally { |
| 2955 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2956 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2960 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2961 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2962 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2963 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2964 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2965 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2966 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2967 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2968 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | final long identity = Binder.clearCallingIdentity(); |
| 2970 | try { |
| 2971 | final Phone phone = getPhone(subId); |
| 2972 | if (phone != null) { |
| 2973 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2974 | } |
| 2975 | } finally { |
| 2976 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2977 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2981 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2984 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2985 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2986 | |
| 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| 2989 | final Phone phone = getPhone(subId); |
| 2990 | if (phone == null) { |
| 2991 | return false; |
| 2992 | } |
| 2993 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2994 | toggleRadioOnOffForSubscriber(subId); |
| 2995 | } |
| 2996 | return true; |
| 2997 | } finally { |
| 2998 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2999 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3000 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3001 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3002 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 3003 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3004 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 3005 | if (!mApp.getResources().getBoolean( |
| 3006 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3007 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3008 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 3009 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3010 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3011 | /* |
| 3012 | * If any of the Radios are available, it will need to be |
| 3013 | * shutdown. So return true if any Radio is available. |
| 3014 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | final long identity = Binder.clearCallingIdentity(); |
| 3016 | try { |
| 3017 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3018 | Phone phone = PhoneFactory.getPhone(i); |
| 3019 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3020 | } |
| 3021 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3022 | return false; |
| 3023 | } finally { |
| 3024 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3025 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3029 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | enforceModifyPermission(); |
| 3031 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3032 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3033 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3034 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3035 | final long identity = Binder.clearCallingIdentity(); |
| 3036 | try { |
| 3037 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3038 | logv("Shutting down Phone " + i); |
| 3039 | shutdownRadioUsingPhoneId(i); |
| 3040 | } |
| 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3047 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3048 | if (phone != null && phone.isRadioAvailable()) { |
| 3049 | phone.shutdownRadio(); |
| 3050 | } |
| 3051 | } |
| 3052 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3053 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3054 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3056 | if (!turnOn) { |
| 3057 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3058 | } |
| 3059 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3060 | final long identity = Binder.clearCallingIdentity(); |
| 3061 | try { |
| 3062 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3063 | if (defaultPhone != null) { |
| 3064 | defaultPhone.setRadioPower(turnOn); |
| 3065 | return true; |
| 3066 | } else { |
| 3067 | loge("There's no default phone."); |
| 3068 | return false; |
| 3069 | } |
| 3070 | } finally { |
| 3071 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3072 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3075 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3076 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3077 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3078 | if (!turnOn) { |
| 3079 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3080 | + ",callingPackage=" + getCurrentPackageName()); |
| 3081 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | final Phone phone = getPhone(subId); |
| 3085 | if (phone != null) { |
| 3086 | phone.setRadioPower(turnOn); |
| 3087 | return true; |
| 3088 | } else { |
| 3089 | return false; |
| 3090 | } |
| 3091 | } finally { |
| 3092 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3093 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3094 | } |
| 3095 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3096 | /** |
| 3097 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3098 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3099 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3100 | * powering it off, and these radio off votes will be cleared. |
| 3101 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3102 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3103 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3104 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3105 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3106 | * check its vote. |
| 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 requestRadioPowerOffForReason(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, "requestRadioPowerOffForReason"); |
| 3118 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3119 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3120 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3121 | final long identity = Binder.clearCallingIdentity(); |
| 3122 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3123 | boolean result = false; |
| 3124 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3125 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3126 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3127 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3128 | if (!result) { |
| 3129 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3130 | } |
| 3131 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | /** |
| 3138 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3139 | * {@link requestRadioPowerOffForReason}. |
| 3140 | * |
| 3141 | * @param subId The subscription ID. |
| 3142 | * @param reason The reason for powering off radio. |
| 3143 | * @return true on success and false on failure. |
| 3144 | */ |
| 3145 | public boolean clearRadioPowerOffForReason(int subId, |
| 3146 | @TelephonyManager.RadioPowerReason int reason) { |
| 3147 | enforceModifyPermission(); |
| 3148 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3149 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3150 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3151 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3152 | final long identity = Binder.clearCallingIdentity(); |
| 3153 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3154 | boolean result = false; |
| 3155 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3156 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3157 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3158 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3159 | if (!result) { |
| 3160 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3161 | } |
| 3162 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3163 | } finally { |
| 3164 | Binder.restoreCallingIdentity(identity); |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | /** |
| 3169 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3170 | * |
| 3171 | * @param subId The subscription ID. |
| 3172 | * @param callingPackage The package making the call. |
| 3173 | * @param callingFeatureId The feature in the package. |
| 3174 | * @return List of reasons for powering off radio. |
| 3175 | */ |
| 3176 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3177 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3178 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3179 | enforceTelephonyFeatureWithException(callingPackage, |
| 3180 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3181 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3182 | final long identity = Binder.clearCallingIdentity(); |
| 3183 | List result = new ArrayList(); |
| 3184 | try { |
| 3185 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3186 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3187 | return result; |
| 3188 | } |
| 3189 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3190 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3191 | if (phone != null) { |
| 3192 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3193 | } else { |
| 3194 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3195 | } |
| 3196 | } finally { |
| 3197 | Binder.restoreCallingIdentity(identity); |
| 3198 | } |
| 3199 | return result; |
| 3200 | } |
| 3201 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3202 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3203 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3204 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3207 | enforceTelephonyFeatureWithException(callingPackage, |
| 3208 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3212 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3213 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3214 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3215 | phone.getDataSettingsManager().setDataEnabled( |
| 3216 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3217 | return true; |
| 3218 | } else { |
| 3219 | return false; |
| 3220 | } |
| 3221 | } finally { |
| 3222 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3223 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3226 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3227 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3228 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3229 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3231 | enforceTelephonyFeatureWithException(callingPackage, |
| 3232 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3233 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3234 | final long identity = Binder.clearCallingIdentity(); |
| 3235 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3236 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3237 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3238 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3239 | phone.getDataSettingsManager().setDataEnabled( |
| 3240 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3241 | return true; |
| 3242 | } else { |
| 3243 | return false; |
| 3244 | } |
| 3245 | } finally { |
| 3246 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3250 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3251 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3252 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3253 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | final long identity = Binder.clearCallingIdentity(); |
| 3256 | try { |
| 3257 | final Phone phone = getPhone(subId); |
| 3258 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3259 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3260 | } else { |
| 3261 | return false; |
| 3262 | } |
| 3263 | } finally { |
| 3264 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3265 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3269 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3272 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3273 | enforceCallPermission(); |
| 3274 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3275 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3276 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3277 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3278 | final long identity = Binder.clearCallingIdentity(); |
| 3279 | try { |
| 3280 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3281 | return; |
| 3282 | } |
| 3283 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3284 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3285 | } finally { |
| 3286 | Binder.restoreCallingIdentity(identity); |
| 3287 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3288 | }; |
| 3289 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3290 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3291 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3292 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3293 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3294 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3296 | final long identity = Binder.clearCallingIdentity(); |
| 3297 | try { |
| 3298 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3299 | return false; |
| 3300 | } |
| 3301 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3304 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3307 | /** |
| 3308 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3309 | * tag on getCallState Binder call. |
| 3310 | */ |
| 3311 | @Deprecated |
| 3312 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3313 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3314 | if (CompatChanges.isChangeEnabled( |
| 3315 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3316 | Binder.getCallingUid())) { |
| 3317 | // Do not allow this API to be called on API version 31+, it should only be |
| 3318 | // called on old apps using this Binder call directly. |
| 3319 | throw new SecurityException("This method can only be used for applications " |
| 3320 | + "targeting API version 30 or less."); |
| 3321 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3322 | final long identity = Binder.clearCallingIdentity(); |
| 3323 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3324 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3325 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3326 | } finally { |
| 3327 | Binder.restoreCallingIdentity(identity); |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | @Override |
| 3332 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3333 | if (CompatChanges.isChangeEnabled( |
| 3334 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3335 | Binder.getCallingUid())) { |
| 3336 | // Check READ_PHONE_STATE for API version 31+ |
| 3337 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3338 | featureId, "getCallStateForSubscription")) { |
| 3339 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3340 | + "targeting API level 31+."); |
| 3341 | } |
| 3342 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3343 | |
| 3344 | enforceTelephonyFeatureWithException(callingPackage, |
| 3345 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3346 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3347 | final long identity = Binder.clearCallingIdentity(); |
| 3348 | try { |
| 3349 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3350 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3351 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3352 | } finally { |
| 3353 | Binder.restoreCallingIdentity(identity); |
| 3354 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3357 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3358 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3359 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | @Override |
| 3363 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3364 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3365 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3366 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | final long identity = Binder.clearCallingIdentity(); |
| 3368 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3369 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3370 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3371 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3372 | } else { |
| 3373 | return PhoneConstantConversions.convertDataState( |
| 3374 | PhoneConstants.DataState.DISCONNECTED); |
| 3375 | } |
| 3376 | } finally { |
| 3377 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3378 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3381 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3382 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3383 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3387 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3388 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3389 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3390 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3391 | final long identity = Binder.clearCallingIdentity(); |
| 3392 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3393 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3394 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3395 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3396 | } else { |
| 3397 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3398 | } |
| 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3401 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3405 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3406 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3407 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3408 | |
| 3409 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3410 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3411 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3412 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3413 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3414 | .setCallingPid(Binder.getCallingPid()) |
| 3415 | .setCallingUid(Binder.getCallingUid()) |
| 3416 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3417 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3418 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3419 | .build()); |
| 3420 | switch (locationResult) { |
| 3421 | case DENIED_HARD: |
| 3422 | throw new SecurityException("Not allowed to access cell location"); |
| 3423 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3424 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3425 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3428 | enforceTelephonyFeatureWithException(callingPackage, |
| 3429 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3430 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3431 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3432 | final long identity = Binder.clearCallingIdentity(); |
| 3433 | try { |
| 3434 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3435 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3436 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(identity); |
| 3439 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3442 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3443 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3444 | if (!mApp.getResources().getBoolean( |
| 3445 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3446 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3447 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3448 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3449 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3450 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3451 | // registered cell info, so return a NULL country instead. |
| 3452 | final long identity = Binder.clearCallingIdentity(); |
| 3453 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3454 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3455 | // Get default phone in this case. |
| 3456 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3457 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3458 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3459 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3460 | if (phone == null) return ""; |
| 3461 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3462 | if (sst == null) return ""; |
| 3463 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3464 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3465 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3466 | } finally { |
| 3467 | Binder.restoreCallingIdentity(identity); |
| 3468 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3471 | /** |
| 3472 | * This method was removed due to potential issues caused by performing partial |
| 3473 | * updates of service state, and lack of a credible use case. |
| 3474 | * |
| 3475 | * This has the ability to break the telephony implementation by disabling notification of |
| 3476 | * changes in device connectivity. DO NOT USE THIS! |
| 3477 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3478 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3479 | public void enableLocationUpdates() { |
| 3480 | mApp.enforceCallingOrSelfPermission( |
| 3481 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3484 | /** |
| 3485 | * This method was removed due to potential issues caused by performing partial |
| 3486 | * updates of service state, and lack of a credible use case. |
| 3487 | * |
| 3488 | * This has the ability to break the telephony implementation by disabling notification of |
| 3489 | * changes in device connectivity. DO NOT USE THIS! |
| 3490 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3491 | @Override |
| 3492 | public void disableLocationUpdates() { |
| 3493 | mApp.enforceCallingOrSelfPermission( |
| 3494 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | @Override |
| 3498 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3499 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3500 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3501 | try { |
| 3502 | mApp.getSystemService(AppOpsManager.class) |
| 3503 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3504 | } catch (SecurityException e) { |
| 3505 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3506 | throw e; |
| 3507 | } |
| 3508 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3509 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3510 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3511 | throw new SecurityException( |
| 3512 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3513 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3514 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3515 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3516 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3517 | return null; |
| 3518 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3519 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3520 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3521 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3522 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3523 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3524 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3525 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3526 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3527 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3528 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3529 | for (CellInfo ci : info) { |
| 3530 | if (ci instanceof CellInfoGsm) { |
| 3531 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3532 | } else if (ci instanceof CellInfoWcdma) { |
| 3533 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3535 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3536 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3539 | private List<CellInfo> getCachedCellInfo() { |
| 3540 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3541 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3542 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3543 | if (info != null) cellInfos.addAll(info); |
| 3544 | } |
| 3545 | return cellInfos; |
| 3546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3547 | |
| 3548 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3549 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3550 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3551 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3552 | |
| 3553 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3554 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3555 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3556 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3557 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3558 | .setCallingPid(Binder.getCallingPid()) |
| 3559 | .setCallingUid(Binder.getCallingUid()) |
| 3560 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3561 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3562 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3563 | .build()); |
| 3564 | switch (locationResult) { |
| 3565 | case DENIED_HARD: |
| 3566 | throw new SecurityException("Not allowed to access cell info"); |
| 3567 | case DENIED_SOFT: |
| 3568 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3569 | } |
| 3570 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3571 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3572 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3573 | return getCachedCellInfo(); |
| 3574 | } |
| 3575 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3576 | enforceTelephonyFeatureWithException(callingPackage, |
| 3577 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3578 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3579 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3580 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
| 3583 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3584 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3585 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3586 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | if (info != null) cellInfos.addAll(info); |
| 3588 | } |
| 3589 | return cellInfos; |
| 3590 | } finally { |
| 3591 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3592 | } |
| 3593 | } |
| 3594 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3595 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3596 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3597 | String callingFeatureId) { |
| 3598 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3599 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3603 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3604 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3605 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3606 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3609 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3610 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3611 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3612 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3613 | |
| 3614 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3615 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3616 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3617 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3618 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3619 | .setCallingPid(Binder.getCallingPid()) |
| 3620 | .setCallingUid(Binder.getCallingUid()) |
| 3621 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3622 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3623 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3624 | .build()); |
| 3625 | switch (locationResult) { |
| 3626 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3627 | if (TelephonyPermissions |
| 3628 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3629 | // Safetynet logging for b/154934934 |
| 3630 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3631 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3632 | throw new SecurityException("Not allowed to access cell info"); |
| 3633 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3634 | if (TelephonyPermissions |
| 3635 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3636 | // Safetynet logging for b/154934934 |
| 3637 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3638 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3639 | try { |
| 3640 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3641 | } catch (RemoteException re) { |
| 3642 | // Drop without consequences |
| 3643 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3644 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3647 | enforceTelephonyFeatureWithException(callingPackage, |
| 3648 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3649 | |
| 3650 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3651 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3652 | |
| 3653 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3654 | } |
| 3655 | |
| 3656 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3657 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3658 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3659 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | |
| 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3663 | Phone phone = getPhone(subId); |
| 3664 | if (phone == null) { |
| 3665 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3666 | } else { |
| 3667 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(identity); |
| 3671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3674 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3675 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3676 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3677 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3678 | return null; |
| 3679 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3680 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3681 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3682 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3683 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3684 | return null; |
| 3685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3686 | |
| 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | return phone.getImei(); |
| 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
| 3692 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3696 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3697 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3698 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3699 | callingFeatureId, "getPrimaryImei")) { |
| 3700 | throw new SecurityException("Caller does not have permission"); |
| 3701 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3702 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3703 | final long identity = Binder.clearCallingIdentity(); |
| 3704 | try { |
| 3705 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3706 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3707 | return phone.getImei(); |
| 3708 | } |
| 3709 | } |
| 3710 | throw new UnsupportedOperationException("Operation not supported"); |
| 3711 | } finally { |
| 3712 | Binder.restoreCallingIdentity(identity); |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3717 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3718 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3719 | String tac = null; |
| 3720 | if (phone != null) { |
| 3721 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3722 | try { |
| 3723 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3724 | } catch (IndexOutOfBoundsException e) { |
| 3725 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3726 | return null; |
| 3727 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3728 | } |
| 3729 | return tac; |
| 3730 | } |
| 3731 | |
| 3732 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3733 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3734 | try { |
| 3735 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3736 | } catch (SecurityException se) { |
| 3737 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3738 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3739 | + Binder.getCallingUid()); |
| 3740 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3741 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3742 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3743 | return null; |
| 3744 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3745 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3746 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3747 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3748 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3749 | return null; |
| 3750 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3752 | enforceTelephonyFeatureWithException(callingPackage, |
| 3753 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3754 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | return phone.getMeid(); |
| 3758 | } finally { |
| 3759 | Binder.restoreCallingIdentity(identity); |
| 3760 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3764 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3765 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3766 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3767 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3768 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3769 | String manufacturerCode = null; |
| 3770 | if (phone != null) { |
| 3771 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3772 | try { |
| 3773 | manufacturerCode = |
| 3774 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3775 | } catch (IndexOutOfBoundsException e) { |
| 3776 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3777 | return null; |
| 3778 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3779 | } |
| 3780 | return manufacturerCode; |
| 3781 | } |
| 3782 | |
| 3783 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3784 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3785 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3786 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3787 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3788 | return null; |
| 3789 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3790 | int subId = phone.getSubId(); |
| 3791 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3792 | mApp, subId, callingPackage, callingFeatureId, |
| 3793 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3794 | return null; |
| 3795 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3797 | enforceTelephonyFeatureWithException(callingPackage, |
| 3798 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3799 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | final long identity = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | return phone.getDeviceSvn(); |
| 3803 | } finally { |
| 3804 | Binder.restoreCallingIdentity(identity); |
| 3805 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3806 | } |
| 3807 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3808 | @Override |
| 3809 | public int getSubscriptionCarrierId(int subId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3810 | if (!mApp.getResources().getBoolean( |
| 3811 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3812 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3813 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3814 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3815 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3816 | final long identity = Binder.clearCallingIdentity(); |
| 3817 | try { |
| 3818 | final Phone phone = getPhone(subId); |
| 3819 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3820 | } finally { |
| 3821 | Binder.restoreCallingIdentity(identity); |
| 3822 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | @Override |
| 3826 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3827 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3828 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3829 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
| 3832 | final Phone phone = getPhone(subId); |
| 3833 | return phone == null ? null : phone.getCarrierName(); |
| 3834 | } finally { |
| 3835 | Binder.restoreCallingIdentity(identity); |
| 3836 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3837 | } |
| 3838 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3839 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3840 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3841 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3842 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3843 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3844 | final long identity = Binder.clearCallingIdentity(); |
| 3845 | try { |
| 3846 | final Phone phone = getPhone(subId); |
| 3847 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3848 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3849 | } finally { |
| 3850 | Binder.restoreCallingIdentity(identity); |
| 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3855 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3856 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3857 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3858 | "getSubscriptionSpecificCarrierName"); |
| 3859 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3860 | final long identity = Binder.clearCallingIdentity(); |
| 3861 | try { |
| 3862 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3863 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3864 | } finally { |
| 3865 | Binder.restoreCallingIdentity(identity); |
| 3866 | } |
| 3867 | } |
| 3868 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3869 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3870 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3871 | if (!isSubscriptionMccMnc) { |
| 3872 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3873 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3874 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3875 | if (phone == null) { |
| 3876 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3877 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3878 | |
| 3879 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3880 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3881 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3882 | final long identity = Binder.clearCallingIdentity(); |
| 3883 | try { |
| 3884 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3885 | } finally { |
| 3886 | Binder.restoreCallingIdentity(identity); |
| 3887 | } |
| 3888 | } |
| 3889 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3890 | // |
| 3891 | // Internal helper methods. |
| 3892 | // |
| 3893 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3894 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3895 | * Make sure the caller is the calling package itself |
| 3896 | * |
| 3897 | * @throws SecurityException if the caller is not the calling package |
| 3898 | */ |
| 3899 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3900 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3901 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3902 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3903 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3904 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3905 | } catch (PackageManager.NameNotFoundException e) { |
| 3906 | // packageUid is -1 |
| 3907 | } |
| 3908 | if (packageUid != callingUid) { |
| 3909 | throw new SecurityException(message + ": Package " + callingPackage |
| 3910 | + " does not belong to " + callingUid); |
| 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3915 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3916 | * |
| 3917 | * @throws SecurityException if the caller does not have the required permission |
| 3918 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3919 | @VisibleForTesting |
| 3920 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3921 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3922 | } |
| 3923 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3924 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3925 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3926 | * |
| 3927 | * @throws SecurityException if the caller does not have the required permission |
| 3928 | */ |
| 3929 | @VisibleForTesting |
| 3930 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3931 | enforceReadPermission(null); |
| 3932 | } |
| 3933 | |
| 3934 | /** |
| 3935 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3936 | * |
| 3937 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3938 | */ |
| 3939 | @VisibleForTesting |
| 3940 | public void enforceReadPermission(String msg) { |
| 3941 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3942 | } |
| 3943 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3944 | private void enforceActiveEmergencySessionPermission() { |
| 3945 | mApp.enforceCallingOrSelfPermission( |
| 3946 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3947 | } |
| 3948 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3949 | /** |
| 3950 | * Make sure the caller has the CALL_PHONE permission. |
| 3951 | * |
| 3952 | * @throws SecurityException if the caller does not have the required permission |
| 3953 | */ |
| 3954 | private void enforceCallPermission() { |
| 3955 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3956 | } |
| 3957 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3958 | private void enforceSettingsPermission() { |
| 3959 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3960 | } |
| 3961 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3962 | private void enforceRebootPermission() { |
| 3963 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3964 | } |
| 3965 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3966 | /** |
| 3967 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3968 | * @param message - log message to print. |
| 3969 | * @throws SecurityException if the caller does not have the required permission |
| 3970 | */ |
| 3971 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3972 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3973 | } |
| 3974 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3975 | /** |
| 3976 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3977 | * @param message - log message to print. |
| 3978 | * @throws SecurityException if the caller does not have the required permission |
| 3979 | */ |
| 3980 | private void enforcePackageUsageStatsPermission(String message) { |
| 3981 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3982 | } |
| 3983 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3984 | private String createTelUrl(String number) { |
| 3985 | if (TextUtils.isEmpty(number)) { |
| 3986 | return null; |
| 3987 | } |
| 3988 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3989 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3992 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3993 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3996 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3997 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4000 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 4001 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4004 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4005 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4006 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4007 | } |
| 4008 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4009 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4010 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 4011 | if (!mApp.getResources().getBoolean( |
| 4012 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 4013 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4014 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4015 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | final long identity = Binder.clearCallingIdentity(); |
| 4018 | try { |
| 4019 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4020 | if (phone == null) { |
| 4021 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4022 | } else { |
| 4023 | return phone.getPhoneType(); |
| 4024 | } |
| 4025 | } finally { |
| 4026 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4027 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | /** |
| 4031 | * Returns the CDMA ERI icon index to display |
| 4032 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4033 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4034 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4035 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4036 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4039 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4040 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4041 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4042 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4043 | mApp, subId, callingPackage, callingFeatureId, |
| 4044 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4045 | return -1; |
| 4046 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4047 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4048 | enforceTelephonyFeatureWithException(callingPackage, |
| 4049 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4050 | "getCdmaEriIconIndexForSubscriber"); |
| 4051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
| 4054 | final Phone phone = getPhone(subId); |
| 4055 | if (phone != null) { |
| 4056 | return phone.getCdmaEriIconIndex(); |
| 4057 | } else { |
| 4058 | return -1; |
| 4059 | } |
| 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4062 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | /** |
| 4066 | * Returns the CDMA ERI icon mode, |
| 4067 | * 0 - ON |
| 4068 | * 1 - FLASHING |
| 4069 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4070 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4071 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4072 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4073 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4076 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4077 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4078 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4079 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4080 | mApp, subId, callingPackage, callingFeatureId, |
| 4081 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4082 | return -1; |
| 4083 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4084 | |
| 4085 | final long identity = Binder.clearCallingIdentity(); |
| 4086 | try { |
| 4087 | final Phone phone = getPhone(subId); |
| 4088 | if (phone != null) { |
| 4089 | return phone.getCdmaEriIconMode(); |
| 4090 | } else { |
| 4091 | return -1; |
| 4092 | } |
| 4093 | } finally { |
| 4094 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4095 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | /** |
| 4099 | * Returns the CDMA ERI text, |
| 4100 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4101 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4102 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4103 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4104 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4107 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4108 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4109 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4110 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4111 | mApp, subId, callingPackage, callingFeatureId, |
| 4112 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4113 | return null; |
| 4114 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4115 | |
| 4116 | final long identity = Binder.clearCallingIdentity(); |
| 4117 | try { |
| 4118 | final Phone phone = getPhone(subId); |
| 4119 | if (phone != null) { |
| 4120 | return phone.getCdmaEriText(); |
| 4121 | } else { |
| 4122 | return null; |
| 4123 | } |
| 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4130 | * Returns the CDMA MDN. |
| 4131 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4132 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4133 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4135 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4136 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4137 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4138 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4139 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | final long identity = Binder.clearCallingIdentity(); |
| 4141 | try { |
| 4142 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4143 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4144 | return phone.getLine1Number(); |
| 4145 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4146 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4147 | return null; |
| 4148 | } |
| 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * Returns the CDMA MIN. |
| 4156 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4157 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4158 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4160 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4161 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4162 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4163 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4165 | final long identity = Binder.clearCallingIdentity(); |
| 4166 | try { |
| 4167 | final Phone phone = getPhone(subId); |
| 4168 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4169 | return phone.getCdmaMin(); |
| 4170 | } else { |
| 4171 | return null; |
| 4172 | } |
| 4173 | } finally { |
| 4174 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4175 | } |
| 4176 | } |
| 4177 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4178 | @Override |
| 4179 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4180 | INumberVerificationCallback callback, String callingPackage) { |
| 4181 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4182 | != PERMISSION_GRANTED) { |
| 4183 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4184 | } |
| 4185 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4186 | |
| 4187 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4188 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4189 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4190 | + "calling package: " + callingPackage |
| 4191 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4192 | } |
| 4193 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4194 | enforceTelephonyFeatureWithException(callingPackage, |
| 4195 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4196 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4197 | if (range == null) { |
| 4198 | throw new NullPointerException("Range must be non-null"); |
| 4199 | } |
| 4200 | |
| 4201 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4202 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4203 | |
| 4204 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4205 | } |
| 4206 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4207 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4208 | * Returns true if CDMA provisioning needs to run. |
| 4209 | */ |
| 4210 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4211 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4212 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | final long identity = Binder.clearCallingIdentity(); |
| 4215 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4216 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4217 | } finally { |
| 4218 | Binder.restoreCallingIdentity(identity); |
| 4219 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4223 | * Sets the voice mail number of a given subId. |
| 4224 | */ |
| 4225 | @Override |
| 4226 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4227 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4228 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4229 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4230 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4231 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4232 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4233 | final long identity = Binder.clearCallingIdentity(); |
| 4234 | try { |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 4235 | Boolean success = (Boolean) sendRequest( |
| 4236 | CMD_SET_VOICEMAIL_NUMBER, |
| 4237 | new Pair<String, String>(alphaTag, number), |
| 4238 | new Integer(subId), |
| 4239 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
| 4240 | if (success == null) return false; // most likely due to a timeout |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4241 | return success; |
| 4242 | } finally { |
| 4243 | Binder.restoreCallingIdentity(identity); |
| 4244 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4245 | } |
| 4246 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4247 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4248 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4249 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4250 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4251 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4252 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4253 | throw new SecurityException("caller must be system dialer"); |
| 4254 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4255 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4256 | enforceTelephonyFeatureWithException(callingPackage, |
| 4257 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4258 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | final long identity = Binder.clearCallingIdentity(); |
| 4260 | try { |
| 4261 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4262 | if (phoneAccountHandle == null) { |
| 4263 | return null; |
| 4264 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4265 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4266 | } finally { |
| 4267 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4268 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4272 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4273 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4274 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4276 | mApp, subId, callingPackage, callingFeatureId, |
| 4277 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4278 | return null; |
| 4279 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4280 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4281 | enforceTelephonyFeatureWithException(callingPackage, |
| 4282 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4283 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4286 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4287 | } finally { |
| 4288 | Binder.restoreCallingIdentity(identity); |
| 4289 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4293 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4294 | VisualVoicemailSmsFilterSettings settings) { |
| 4295 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4296 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4297 | enforceTelephonyFeatureWithException(callingPackage, |
| 4298 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | final long identity = Binder.clearCallingIdentity(); |
| 4300 | try { |
| 4301 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4302 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4303 | } finally { |
| 4304 | Binder.restoreCallingIdentity(identity); |
| 4305 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4309 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4310 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4311 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4312 | enforceTelephonyFeatureWithException(callingPackage, |
| 4313 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4314 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4315 | final long identity = Binder.clearCallingIdentity(); |
| 4316 | try { |
| 4317 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4318 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
| 4321 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4325 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4326 | String callingPackage, int subId) { |
| 4327 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | |
| 4329 | final long identity = Binder.clearCallingIdentity(); |
| 4330 | try { |
| 4331 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4332 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4333 | } finally { |
| 4334 | Binder.restoreCallingIdentity(identity); |
| 4335 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4339 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4340 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | |
| 4342 | final long identity = Binder.clearCallingIdentity(); |
| 4343 | try { |
| 4344 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4345 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4346 | } finally { |
| 4347 | Binder.restoreCallingIdentity(identity); |
| 4348 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4352 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4353 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4354 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4355 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4356 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4357 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4358 | |
| 4359 | enforceTelephonyFeatureWithException(callingPackage, |
| 4360 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4361 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4362 | SmsController smsController = PhoneFactory.getSmsController(); |
Nikhil Kumar | deebd75 | 2024-08-14 14:49:06 +0100 | [diff] [blame] | 4363 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, |
| 4364 | Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number, |
| 4365 | port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4366 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4367 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4368 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4369 | * Sets the voice activation state of a given subId. |
| 4370 | */ |
| 4371 | @Override |
| 4372 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4374 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4375 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4376 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4377 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4379 | final long identity = Binder.clearCallingIdentity(); |
| 4380 | try { |
| 4381 | final Phone phone = getPhone(subId); |
| 4382 | if (phone != null) { |
| 4383 | phone.setVoiceActivationState(activationState); |
| 4384 | } else { |
| 4385 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4386 | } |
| 4387 | } finally { |
| 4388 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4389 | } |
| 4390 | } |
| 4391 | |
| 4392 | /** |
| 4393 | * Sets the data activation state of a given subId. |
| 4394 | */ |
| 4395 | @Override |
| 4396 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4397 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4398 | mApp, subId, "setDataActivationState"); |
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(getCurrentPackageName(), |
| 4401 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4402 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | final long identity = Binder.clearCallingIdentity(); |
| 4404 | try { |
| 4405 | final Phone phone = getPhone(subId); |
| 4406 | if (phone != null) { |
| 4407 | phone.setDataActivationState(activationState); |
| 4408 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4409 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4410 | } |
| 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | /** |
| 4417 | * Returns the voice activation state of a given subId. |
| 4418 | */ |
| 4419 | @Override |
| 4420 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4421 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4422 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4423 | enforceTelephonyFeatureWithException(callingPackage, |
| 4424 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4425 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4426 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | final long identity = Binder.clearCallingIdentity(); |
| 4428 | try { |
| 4429 | if (phone != null) { |
| 4430 | return phone.getVoiceActivationState(); |
| 4431 | } else { |
| 4432 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4433 | } |
| 4434 | } finally { |
| 4435 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4436 | } |
| 4437 | } |
| 4438 | |
| 4439 | /** |
| 4440 | * Returns the data activation state of a given subId. |
| 4441 | */ |
| 4442 | @Override |
| 4443 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4444 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4445 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4446 | enforceTelephonyFeatureWithException(callingPackage, |
| 4447 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4448 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4449 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | final long identity = Binder.clearCallingIdentity(); |
| 4451 | try { |
| 4452 | if (phone != null) { |
| 4453 | return phone.getDataActivationState(); |
| 4454 | } else { |
| 4455 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4456 | } |
| 4457 | } finally { |
| 4458 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4463 | * Returns the unread count of voicemails for a subId |
| 4464 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4465 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4466 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4467 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4468 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4469 | mApp, subId, callingPackage, callingFeatureId, |
| 4470 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4471 | return 0; |
| 4472 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4473 | final long identity = Binder.clearCallingIdentity(); |
| 4474 | try { |
| 4475 | final Phone phone = getPhone(subId); |
| 4476 | if (phone != null) { |
| 4477 | return phone.getVoiceMessageCount(); |
| 4478 | } else { |
| 4479 | return 0; |
| 4480 | } |
| 4481 | } finally { |
| 4482 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4487 | * returns true, if the device is in a state where both voice and data |
| 4488 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4489 | */ |
| 4490 | @Override |
| 4491 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4492 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4493 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4494 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4495 | final long identity = Binder.clearCallingIdentity(); |
| 4496 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4497 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4498 | } finally { |
| 4499 | Binder.restoreCallingIdentity(identity); |
| 4500 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4504 | * Send the dialer code if called from the current default dialer or the caller has |
| 4505 | * carrier privilege. |
| 4506 | * @param inputCode The dialer code to send |
| 4507 | */ |
| 4508 | @Override |
| 4509 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4510 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4511 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4512 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4513 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4514 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4515 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4516 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4517 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4519 | enforceTelephonyFeatureWithException(callingPackage, |
| 4520 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4521 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4524 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(identity); |
| 4527 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4528 | } |
| 4529 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4530 | @Override |
| 4531 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4532 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4533 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4534 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4535 | |
| 4536 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4537 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4538 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4539 | final long identity = Binder.clearCallingIdentity(); |
| 4540 | try { |
| 4541 | if (!isActiveSubscription(subId)) { |
| 4542 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4543 | } |
| 4544 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4545 | } finally { |
| 4546 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4547 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4550 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4551 | public boolean isInEmergencySmsMode() { |
| 4552 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4553 | |
| 4554 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4555 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4556 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4557 | final long identity = Binder.clearCallingIdentity(); |
| 4558 | try { |
| 4559 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4560 | if (phone.isInEmergencySmsMode()) { |
| 4561 | return true; |
| 4562 | } |
| 4563 | } |
| 4564 | } finally { |
| 4565 | Binder.restoreCallingIdentity(identity); |
| 4566 | } |
| 4567 | return false; |
| 4568 | } |
| 4569 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4570 | /** |
| 4571 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4572 | * @param subId The subscription to use to check the configuration. |
| 4573 | * @param c The callback that will be used to send the result. |
| 4574 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4575 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4576 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4577 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4578 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4579 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4580 | |
| 4581 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4582 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4583 | "IMS not available on device."); |
| 4584 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4585 | final long token = Binder.clearCallingIdentity(); |
| 4586 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4587 | int slotId = getSlotIndexOrException(subId); |
| 4588 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4589 | |
| 4590 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4591 | if (controller != null) { |
| 4592 | ImsManager imsManager = controller.getImsManager(subId); |
| 4593 | if (imsManager != null) { |
| 4594 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4595 | } else { |
| 4596 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4597 | } |
| 4598 | } else { |
| 4599 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4600 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4601 | } catch (ImsException e) { |
| 4602 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4603 | } finally { |
| 4604 | Binder.restoreCallingIdentity(token); |
| 4605 | } |
| 4606 | } |
| 4607 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4608 | /** |
| 4609 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4610 | * @param subId The subscription to use to check the configuration. |
| 4611 | * @param c The callback that will be used to send the result. |
| 4612 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4613 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4614 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4615 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4616 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4617 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4618 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4619 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4620 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4621 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4622 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4623 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4624 | if (controller != null) { |
| 4625 | ImsManager imsManager = controller.getImsManager(subId); |
| 4626 | if (imsManager != null) { |
| 4627 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4628 | } else { |
| 4629 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4630 | + "is inactive, ignoring unregister."); |
| 4631 | // If the ImsManager is not valid, just return, since the callback |
| 4632 | // will already have been removed internally. |
| 4633 | } |
| 4634 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(token); |
| 4637 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4638 | } |
| 4639 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4640 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4641 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4642 | * @param subId The subscription to use to check the configuration. |
| 4643 | * @param c The callback that will be used to send the result. |
| 4644 | */ |
| 4645 | @Override |
| 4646 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4647 | throws RemoteException { |
| 4648 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4649 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4650 | |
| 4651 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4652 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4653 | "IMS not available on device."); |
| 4654 | } |
| 4655 | final long token = Binder.clearCallingIdentity(); |
| 4656 | try { |
| 4657 | int slotId = getSlotIndexOrException(subId); |
| 4658 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4659 | |
| 4660 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4661 | if (controller != null) { |
| 4662 | ImsManager imsManager = controller.getImsManager(subId); |
| 4663 | if (imsManager != null) { |
| 4664 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4665 | } else { |
| 4666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4667 | } |
| 4668 | } else { |
| 4669 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4670 | } |
| 4671 | } catch (ImsException e) { |
| 4672 | throw new ServiceSpecificException(e.getCode()); |
| 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(token); |
| 4675 | } |
| 4676 | } |
| 4677 | |
| 4678 | /** |
| 4679 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4680 | * @param subId The subscription to use to check the configuration. |
| 4681 | * @param c The callback that will be used to send the result. |
| 4682 | */ |
| 4683 | @Override |
| 4684 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4685 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4686 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4687 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4688 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4689 | } |
| 4690 | final long token = Binder.clearCallingIdentity(); |
| 4691 | |
| 4692 | try { |
| 4693 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4694 | if (controller != null) { |
| 4695 | ImsManager imsManager = controller.getImsManager(subId); |
| 4696 | if (imsManager != null) { |
| 4697 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4698 | } else { |
| 4699 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4700 | + "is inactive, ignoring unregister."); |
| 4701 | // If the ImsManager is not valid, just return, since the callback |
| 4702 | // will already have been removed internally. |
| 4703 | } |
| 4704 | } |
| 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(token); |
| 4707 | } |
| 4708 | } |
| 4709 | |
| 4710 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4711 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4712 | */ |
| 4713 | @Override |
| 4714 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4715 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4716 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4717 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4718 | "IMS not available on device."); |
| 4719 | } |
| 4720 | final long token = Binder.clearCallingIdentity(); |
| 4721 | try { |
| 4722 | Phone phone = getPhone(subId); |
| 4723 | if (phone == null) { |
| 4724 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4725 | + subId + "'"); |
| 4726 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4727 | } |
| 4728 | phone.getImsRegistrationState(regState -> { |
| 4729 | try { |
| 4730 | consumer.accept((regState == null) |
| 4731 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4732 | } catch (RemoteException e) { |
| 4733 | // Ignore if the remote process is no longer available to call back. |
| 4734 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4735 | } |
| 4736 | }); |
| 4737 | } finally { |
| 4738 | Binder.restoreCallingIdentity(token); |
| 4739 | } |
| 4740 | } |
| 4741 | |
| 4742 | /** |
| 4743 | * Get the transport type for the IMS service registration state. |
| 4744 | */ |
| 4745 | @Override |
| 4746 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4747 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4748 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4749 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4751 | "IMS not available on device."); |
| 4752 | } |
| 4753 | final long token = Binder.clearCallingIdentity(); |
| 4754 | try { |
| 4755 | Phone phone = getPhone(subId); |
| 4756 | if (phone == null) { |
| 4757 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4758 | + subId + "'"); |
| 4759 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4760 | } |
| 4761 | phone.getImsRegistrationTech(regTech -> { |
| 4762 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4763 | int regTechConverted = (regTech == null) |
| 4764 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4765 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4766 | regTechConverted); |
| 4767 | try { |
| 4768 | consumer.accept(regTechConverted); |
| 4769 | } catch (RemoteException e) { |
| 4770 | // Ignore if the remote process is no longer available to call back. |
| 4771 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4772 | } |
| 4773 | }); |
| 4774 | } finally { |
| 4775 | Binder.restoreCallingIdentity(token); |
| 4776 | } |
| 4777 | } |
| 4778 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4779 | /** |
| 4780 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4781 | * @param subId The subscription to use to check the configuration. |
| 4782 | * @param c The callback that will be used to send the result. |
| 4783 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4784 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4785 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4786 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4787 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4788 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4789 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4790 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4791 | "IMS not available on device."); |
| 4792 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4793 | final long token = Binder.clearCallingIdentity(); |
| 4794 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4795 | int slotId = getSlotIndexOrException(subId); |
| 4796 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4797 | |
| 4798 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4799 | if (controller != null) { |
| 4800 | ImsManager imsManager = controller.getImsManager(subId); |
| 4801 | if (imsManager != null) { |
| 4802 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4803 | } else { |
| 4804 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4805 | } |
| 4806 | } else { |
| 4807 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4808 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4809 | } catch (ImsException e) { |
| 4810 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4811 | } finally { |
| 4812 | Binder.restoreCallingIdentity(token); |
| 4813 | } |
| 4814 | } |
| 4815 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4816 | /** |
| 4817 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4818 | * @param subId The subscription to use to check the configuration. |
| 4819 | * @param c The callback that will be used to send the result. |
| 4820 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4821 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4822 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4823 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4824 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4825 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4826 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4827 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4828 | |
| 4829 | final long token = Binder.clearCallingIdentity(); |
| 4830 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4831 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4832 | if (controller != null) { |
| 4833 | ImsManager imsManager = controller.getImsManager(subId); |
| 4834 | if (imsManager != null) { |
| 4835 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4836 | } else { |
| 4837 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4838 | + " is inactive, ignoring unregister."); |
| 4839 | // If the ImsManager is not valid, just return, since the callback |
| 4840 | // will already have been removed internally. |
| 4841 | } |
| 4842 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4843 | } finally { |
| 4844 | Binder.restoreCallingIdentity(token); |
| 4845 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4849 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4850 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4851 | |
| 4852 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4853 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4854 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4855 | final long token = Binder.clearCallingIdentity(); |
| 4856 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4857 | int slotId = getSlotIndexOrException(subId); |
| 4858 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4859 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4860 | } catch (com.android.ims.ImsException e) { |
| 4861 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4862 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4863 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4864 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4865 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(token); |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4872 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4873 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4874 | |
| 4875 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4876 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4877 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4878 | final long token = Binder.clearCallingIdentity(); |
| 4879 | try { |
| 4880 | Phone phone = getPhone(subId); |
| 4881 | if (phone == null) return false; |
| 4882 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4883 | } catch (com.android.ims.ImsException e) { |
| 4884 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4885 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4886 | } finally { |
| 4887 | Binder.restoreCallingIdentity(token); |
| 4888 | } |
| 4889 | } |
| 4890 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4891 | /** |
| 4892 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4893 | * subscription. |
| 4894 | * @param subId The subscription to use to check the configuration. |
| 4895 | * @param callback The callback that will be used to send the result. |
| 4896 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4897 | * @param transportType The transport type of the MmTelFeature capability. |
| 4898 | */ |
| 4899 | @Override |
| 4900 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4901 | int transportType) { |
| 4902 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4903 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4904 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4905 | "IMS not available on device."); |
| 4906 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4907 | final long token = Binder.clearCallingIdentity(); |
| 4908 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4909 | int slotId = getSlotIndex(subId); |
| 4910 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4911 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4912 | + subId + "'"); |
| 4913 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4914 | } |
| 4915 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4916 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4917 | transportType, aBoolean -> { |
| 4918 | try { |
| 4919 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4920 | } catch (RemoteException e) { |
| 4921 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4922 | + "running. Ignore"); |
| 4923 | } |
| 4924 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4925 | } catch (ImsException e) { |
| 4926 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4927 | } finally { |
| 4928 | Binder.restoreCallingIdentity(token); |
| 4929 | } |
| 4930 | } |
| 4931 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4932 | /** |
| 4933 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4934 | * @param subId The subscription to use to check the configuration. |
| 4935 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4936 | @Override |
| 4937 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4938 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4939 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4940 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4941 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4942 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4943 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4944 | final long token = Binder.clearCallingIdentity(); |
| 4945 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4946 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4947 | // 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] | 4948 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4949 | } catch (ImsException e) { |
| 4950 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(token); |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4957 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4959 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4960 | |
| 4961 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4962 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4963 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4964 | final long identity = Binder.clearCallingIdentity(); |
| 4965 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4966 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4967 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4968 | // 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] | 4969 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4970 | } catch (ImsException e) { |
| 4971 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
| 4974 | } |
| 4975 | } |
| 4976 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4977 | /** |
| 4978 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4979 | * @param subId The subscription to use to check the configuration. |
| 4980 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4981 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4982 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4983 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4984 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4985 | |
| 4986 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4987 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4988 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4989 | final long identity = Binder.clearCallingIdentity(); |
| 4990 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4991 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4992 | // 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] | 4993 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4994 | } catch (ImsException e) { |
| 4995 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5002 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5004 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5005 | |
| 5006 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5007 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 5008 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5009 | final long identity = Binder.clearCallingIdentity(); |
| 5010 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5011 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5012 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5013 | // 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] | 5014 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5015 | } catch (ImsException e) { |
| 5016 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5017 | } finally { |
| 5018 | Binder.restoreCallingIdentity(identity); |
| 5019 | } |
| 5020 | } |
| 5021 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5022 | /** |
| 5023 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5024 | * @param subId The subscription to use to check the configuration. |
| 5025 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5026 | @Override |
| 5027 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5028 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5029 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5030 | |
| 5031 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5032 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5033 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [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).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5039 | } catch (ImsException e) { |
| 5040 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5041 | } finally { |
| 5042 | Binder.restoreCallingIdentity(identity); |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5047 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5049 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5050 | |
| 5051 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5052 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5053 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5056 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5057 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5058 | // 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] | 5059 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5060 | } catch (ImsException e) { |
| 5061 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5062 | } finally { |
| 5063 | Binder.restoreCallingIdentity(identity); |
| 5064 | } |
| 5065 | } |
| 5066 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5067 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5068 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5069 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5070 | * @param subId The subscription to use to check the configuration. |
| 5071 | */ |
| 5072 | @Override |
| 5073 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5074 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5075 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5076 | |
| 5077 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5078 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5079 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5080 | final long identity = Binder.clearCallingIdentity(); |
| 5081 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5082 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5083 | // 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] | 5084 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5085 | } catch (ImsException e) { |
| 5086 | throw new ServiceSpecificException(e.getCode()); |
| 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | /** |
| 5093 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5094 | * Requires MODIFY_PHONE_STATE permission. |
| 5095 | * @param subId The subscription to use to check the configuration. |
| 5096 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5097 | * false otherwise |
| 5098 | */ |
| 5099 | @Override |
| 5100 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5102 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5103 | |
| 5104 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5105 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5106 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [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).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5113 | } catch (ImsException e) { |
| 5114 | throw new ServiceSpecificException(e.getCode()); |
| 5115 | } finally { |
| 5116 | Binder.restoreCallingIdentity(identity); |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5121 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5122 | * @param subId The subscription to use to check the configuration. |
| 5123 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5124 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5125 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5126 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5127 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5128 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5129 | |
| 5130 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5131 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5132 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5133 | final long identity = Binder.clearCallingIdentity(); |
| 5134 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5135 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5136 | // 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] | 5137 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5138 | } catch (ImsException e) { |
| 5139 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5140 | } finally { |
| 5141 | Binder.restoreCallingIdentity(identity); |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5146 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5148 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5149 | |
| 5150 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5151 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5152 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5153 | final long identity = Binder.clearCallingIdentity(); |
| 5154 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5155 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5156 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5157 | // 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] | 5158 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5159 | } catch (ImsException e) { |
| 5160 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
| 5163 | } |
| 5164 | } |
| 5165 | |
| 5166 | @Override |
| 5167 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5169 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5170 | |
| 5171 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5172 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5173 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5174 | final long identity = Binder.clearCallingIdentity(); |
| 5175 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5176 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5177 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5178 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5179 | } catch (ImsException e) { |
| 5180 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5181 | } finally { |
| 5182 | Binder.restoreCallingIdentity(identity); |
| 5183 | } |
| 5184 | } |
| 5185 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5186 | /** |
| 5187 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5188 | * @param subId The subscription to use to check the configuration. |
| 5189 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5190 | @Override |
| 5191 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5192 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5193 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5194 | |
| 5195 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5196 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5197 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5198 | final long identity = Binder.clearCallingIdentity(); |
| 5199 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5200 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5201 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5202 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5203 | } catch (ImsException e) { |
| 5204 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
| 5207 | } |
| 5208 | } |
| 5209 | |
| 5210 | @Override |
| 5211 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5213 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5214 | |
| 5215 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5216 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5217 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5218 | final long identity = Binder.clearCallingIdentity(); |
| 5219 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5220 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5221 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5222 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5223 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5224 | } catch (ImsException e) { |
| 5225 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5226 | } finally { |
| 5227 | Binder.restoreCallingIdentity(identity); |
| 5228 | } |
| 5229 | } |
| 5230 | |
| 5231 | @Override |
| 5232 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5233 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5234 | |
| 5235 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5236 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5237 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5240 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5241 | // 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] | 5242 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5243 | } catch (ImsException e) { |
| 5244 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5245 | } finally { |
| 5246 | Binder.restoreCallingIdentity(identity); |
| 5247 | } |
| 5248 | } |
| 5249 | |
| 5250 | @Override |
| 5251 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5252 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5253 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5254 | |
| 5255 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5256 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 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. The |
| 5262 | // 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] | 5263 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5264 | } catch (ImsException e) { |
| 5265 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5266 | } finally { |
| 5267 | Binder.restoreCallingIdentity(identity); |
| 5268 | } |
| 5269 | } |
| 5270 | |
| 5271 | @Override |
| 5272 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5273 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5274 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5275 | |
| 5276 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5277 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5278 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5279 | final long identity = Binder.clearCallingIdentity(); |
| 5280 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5281 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5282 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5283 | // 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] | 5284 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5285 | } catch (ImsException e) { |
| 5286 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5287 | } finally { |
| 5288 | Binder.restoreCallingIdentity(identity); |
| 5289 | } |
| 5290 | } |
| 5291 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5292 | /** |
| 5293 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5294 | * @param subId The subscription to use to check the configuration. |
| 5295 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5296 | @Override |
| 5297 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5298 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5299 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5300 | |
| 5301 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5302 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5303 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5304 | final long identity = Binder.clearCallingIdentity(); |
| 5305 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5306 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5307 | // 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] | 5308 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5309 | } catch (ImsException e) { |
| 5310 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5311 | } finally { |
| 5312 | Binder.restoreCallingIdentity(identity); |
| 5313 | } |
| 5314 | } |
| 5315 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5316 | @Override |
| 5317 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5318 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5319 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5320 | final long identity = Binder.clearCallingIdentity(); |
| 5321 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5322 | if (!isImsAvailableOnDevice()) { |
| 5323 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5324 | "IMS not available on device."); |
| 5325 | } |
| 5326 | int slotId = getSlotIndexOrException(subId); |
| 5327 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5328 | |
| 5329 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5330 | if (controller != null) { |
| 5331 | ImsManager imsManager = controller.getImsManager(subId); |
| 5332 | if (imsManager != null) { |
| 5333 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5334 | } else { |
| 5335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5336 | } |
| 5337 | } else { |
| 5338 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5339 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5340 | } catch (ImsException e) { |
| 5341 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5342 | } finally { |
| 5343 | Binder.restoreCallingIdentity(identity); |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | @Override |
| 5348 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5349 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5350 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5351 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5352 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5353 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5354 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5355 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5356 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5357 | if (controller != null) { |
| 5358 | ImsManager imsManager = controller.getImsManager(subId); |
| 5359 | if (imsManager != null) { |
| 5360 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5361 | } else { |
| 5362 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5363 | + " is inactive, ignoring unregister."); |
| 5364 | // If the ImsManager is not valid, just return, since the callback will already |
| 5365 | // have been removed internally. |
| 5366 | } |
| 5367 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5368 | } finally { |
| 5369 | Binder.restoreCallingIdentity(identity); |
| 5370 | } |
| 5371 | } |
| 5372 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5373 | @Override |
| 5374 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5375 | IFeatureProvisioningCallback callback) { |
| 5376 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5377 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5378 | |
| 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5381 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5382 | } |
| 5383 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5384 | try { |
| 5385 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5386 | if (controller == null) { |
| 5387 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5388 | "Device does not support IMS"); |
| 5389 | } |
| 5390 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5391 | } finally { |
| 5392 | Binder.restoreCallingIdentity(identity); |
| 5393 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | @Override |
| 5397 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5398 | IFeatureProvisioningCallback callback) { |
| 5399 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5400 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5401 | |
| 5402 | final long identity = Binder.clearCallingIdentity(); |
| 5403 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5404 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5405 | } |
| 5406 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5407 | try { |
| 5408 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5409 | if (controller == null) { |
| 5410 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5411 | return; |
| 5412 | } |
| 5413 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5414 | } finally { |
| 5415 | Binder.restoreCallingIdentity(identity); |
| 5416 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5417 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5418 | |
| 5419 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5420 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5421 | message); |
| 5422 | } |
| 5423 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5424 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5425 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5426 | boolean isProvisioned) { |
| 5427 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5428 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5429 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5430 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5431 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +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("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5437 | return; |
| 5438 | } |
| 5439 | controller.setRcsProvisioningStatusForCapability( |
| 5440 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | |
| 5447 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5448 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5449 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5450 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5451 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5452 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5453 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5454 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5455 | final long identity = Binder.clearCallingIdentity(); |
| 5456 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5457 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5458 | if (controller == null) { |
| 5459 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5460 | |
| 5461 | // device does not support IMS, this method will return true always. |
| 5462 | return true; |
| 5463 | } |
| 5464 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
| 5467 | } |
| 5468 | } |
| 5469 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5470 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5471 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5472 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5473 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5474 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5475 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5476 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5477 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5478 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5479 | final long identity = Binder.clearCallingIdentity(); |
| 5480 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5481 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5482 | if (controller == null) { |
| 5483 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5484 | return; |
| 5485 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5486 | controller.setImsProvisioningStatusForCapability(displayPackageName, |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5487 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5488 | } finally { |
| 5489 | Binder.restoreCallingIdentity(identity); |
| 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | @Override |
| 5494 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5495 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5496 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5497 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5498 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5499 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5500 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5501 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5502 | final long identity = Binder.clearCallingIdentity(); |
| 5503 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5504 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5505 | if (controller == null) { |
| 5506 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5507 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5508 | // device does not support IMS, this method will return true always. |
| 5509 | return true; |
| 5510 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5511 | return controller.getImsProvisioningStatusForCapability(displayPackageName, |
| 5512 | subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5513 | } finally { |
| 5514 | Binder.restoreCallingIdentity(identity); |
| 5515 | } |
| 5516 | } |
| 5517 | |
| 5518 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5519 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5520 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5521 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5522 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5523 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5524 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5525 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5526 | final long identity = Binder.clearCallingIdentity(); |
| 5527 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5528 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5529 | if (controller == null) { |
| 5530 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5531 | |
| 5532 | // device does not support IMS, this method will return false |
| 5533 | return false; |
| 5534 | } |
| 5535 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5536 | } finally { |
| 5537 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5538 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5542 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5543 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5544 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5545 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5546 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5547 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5548 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5549 | final long identity = Binder.clearCallingIdentity(); |
| 5550 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5551 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5552 | if (controller == null) { |
| 5553 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5554 | |
| 5555 | // device does not support IMS, this method will return false |
| 5556 | return false; |
| 5557 | } |
| 5558 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5559 | } finally { |
| 5560 | Binder.restoreCallingIdentity(identity); |
| 5561 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5562 | } |
| 5563 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5564 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5565 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5566 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5567 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5568 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5569 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5570 | mApp, subId, "getImsProvisioningInt"); |
| 5571 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5572 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5573 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5574 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5575 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5576 | final long identity = Binder.clearCallingIdentity(); |
| 5577 | try { |
| 5578 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5579 | int slotId = getSlotIndex(subId); |
| 5580 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5581 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5582 | + subId + "' for key:" + key); |
| 5583 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5584 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5585 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5586 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5587 | if (controller == null) { |
| 5588 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5589 | |
| 5590 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5591 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5592 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5593 | int retVal = controller.getProvisioningValue(displayPackageName, subId, |
| 5594 | key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5595 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5596 | return retVal; |
| 5597 | } |
| 5598 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5599 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5600 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5601 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5602 | + subId + "' for key:" + key); |
| 5603 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5604 | } finally { |
| 5605 | Binder.restoreCallingIdentity(identity); |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | @Override |
| 5610 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5611 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5612 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5613 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5614 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5615 | mApp, subId, "getImsProvisioningString"); |
| 5616 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5617 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5618 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5619 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5620 | final long identity = Binder.clearCallingIdentity(); |
| 5621 | try { |
| 5622 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5623 | int slotId = getSlotIndex(subId); |
| 5624 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5625 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5626 | + subId + "' for key:" + key); |
| 5627 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5628 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5629 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5630 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5631 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5632 | + subId + "' for key:" + key); |
| 5633 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5634 | } finally { |
| 5635 | Binder.restoreCallingIdentity(identity); |
| 5636 | } |
| 5637 | } |
| 5638 | |
| 5639 | @Override |
| 5640 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5641 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5642 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5643 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5645 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5646 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5647 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5648 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5649 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5650 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5651 | final long identity = Binder.clearCallingIdentity(); |
| 5652 | try { |
| 5653 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5654 | int slotId = getSlotIndex(subId); |
| 5655 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5656 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5657 | + subId + "' for key:" + key); |
| 5658 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5659 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5660 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5661 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5662 | if (controller == null) { |
| 5663 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5664 | |
| 5665 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5666 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5667 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5668 | int retVal = controller.setProvisioningValue(displayPackageName, subId, key, |
| 5669 | value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5670 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5671 | return retVal; |
| 5672 | } |
| 5673 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5674 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5675 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5676 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5677 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5678 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5679 | } finally { |
| 5680 | Binder.restoreCallingIdentity(identity); |
| 5681 | } |
| 5682 | } |
| 5683 | |
| 5684 | @Override |
| 5685 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5686 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5687 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5688 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5690 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5691 | |
| 5692 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5693 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5694 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5695 | final long identity = Binder.clearCallingIdentity(); |
| 5696 | try { |
| 5697 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5698 | int slotId = getSlotIndex(subId); |
| 5699 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5700 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5701 | + subId + "' for key:" + key); |
| 5702 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5703 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5704 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5705 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5706 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5707 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5708 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5709 | } finally { |
| 5710 | Binder.restoreCallingIdentity(identity); |
| 5711 | } |
| 5712 | } |
| 5713 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5714 | /** |
| 5715 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5716 | * for the given slot ID or no ImsResolver instance has been created. |
| 5717 | * @param slotId The slot ID that the IMS service is created for. |
| 5718 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5719 | */ |
| 5720 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5721 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5722 | ImsFeature.FEATURE_MMTEL)) { |
| 5723 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5724 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5725 | } |
| 5726 | } |
| 5727 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5728 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5729 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5730 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5731 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5732 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5733 | } |
| 5734 | return slotId; |
| 5735 | } |
| 5736 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5737 | private int getSlotIndex(int subId) { |
| 5738 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5739 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5740 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5741 | } |
| 5742 | return slotId; |
| 5743 | } |
| 5744 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5745 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5746 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5747 | */ |
| 5748 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5749 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5750 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5751 | try { |
| 5752 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5753 | } catch (SecurityException se) { |
| 5754 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5755 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5756 | + Binder.getCallingUid()); |
| 5757 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5758 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5759 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5760 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5761 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5762 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5763 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5764 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5765 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5766 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5767 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5768 | enforceTelephonyFeatureWithException(callingPackage, |
| 5769 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5770 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | final long identity = Binder.clearCallingIdentity(); |
| 5772 | try { |
| 5773 | final Phone phone = getPhone(subId); |
| 5774 | if (phone != null) { |
| 5775 | return phone.getServiceState().getDataNetworkType(); |
| 5776 | } else { |
| 5777 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5778 | } |
| 5779 | } finally { |
| 5780 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5781 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | /** |
| 5785 | * Returns the data network type |
| 5786 | */ |
| 5787 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5788 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5789 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5790 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | /** |
| 5794 | * Returns the data network type for a subId |
| 5795 | */ |
| 5796 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5797 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5798 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5799 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5800 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5801 | mApp, functionName)) { |
| 5802 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5803 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5804 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5805 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5806 | } |
| 5807 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5808 | enforceTelephonyFeatureWithException(callingPackage, |
| 5809 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5810 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5811 | final long identity = Binder.clearCallingIdentity(); |
| 5812 | try { |
| 5813 | final Phone phone = getPhone(subId); |
| 5814 | if (phone != null) { |
| 5815 | return phone.getServiceState().getDataNetworkType(); |
| 5816 | } else { |
| 5817 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5818 | } |
| 5819 | } finally { |
| 5820 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5821 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5825 | * Returns the Voice network type for a subId |
| 5826 | */ |
| 5827 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5828 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5829 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5830 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5831 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5832 | mApp, functionName)) { |
| 5833 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5834 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5835 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5836 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5837 | } |
| 5838 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5839 | enforceTelephonyFeatureWithException(callingPackage, |
| 5840 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5841 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | final long identity = Binder.clearCallingIdentity(); |
| 5843 | try { |
| 5844 | final Phone phone = getPhone(subId); |
| 5845 | if (phone != null) { |
| 5846 | return phone.getServiceState().getVoiceNetworkType(); |
| 5847 | } else { |
| 5848 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5849 | } |
| 5850 | } finally { |
| 5851 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5852 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | /** |
| 5856 | * @return true if a ICC card is present |
| 5857 | */ |
| 5858 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5859 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5860 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5861 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5865 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5866 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5867 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5868 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 5869 | if (!mApp.getResources().getBoolean( |
| 5870 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 5871 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5872 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5873 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5874 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5875 | final long identity = Binder.clearCallingIdentity(); |
| 5876 | try { |
| 5877 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5878 | if (phone != null) { |
| 5879 | return phone.getIccCard().hasIccCard(); |
| 5880 | } else { |
| 5881 | return false; |
| 5882 | } |
| 5883 | } finally { |
| 5884 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5885 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | /** |
| 5889 | * Return if the current radio is LTE on CDMA. This |
| 5890 | * is a tri-state return value as for a period of time |
| 5891 | * the mode may be unknown. |
| 5892 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5893 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5894 | * @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] | 5895 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5896 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5897 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5898 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5899 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5900 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5903 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5904 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5905 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5906 | try { |
| 5907 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5908 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5909 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5910 | } |
| 5911 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5912 | enforceTelephonyFeatureWithException(callingPackage, |
| 5913 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5914 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5915 | final long identity = Binder.clearCallingIdentity(); |
| 5916 | try { |
| 5917 | final Phone phone = getPhone(subId); |
| 5918 | if (phone == null) { |
| 5919 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5920 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5921 | return TelephonyProperties.lte_on_cdma_device() |
| 5922 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5923 | } |
| 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5926 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5927 | } |
| 5928 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5929 | /** |
| 5930 | * {@hide} |
| 5931 | * Returns Default subId, 0 in the case of single standby. |
| 5932 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5933 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5934 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5935 | } |
| 5936 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5937 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5938 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5941 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5942 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5943 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5944 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5945 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5946 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5947 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5948 | } |
| 5949 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5950 | /** |
| 5951 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5952 | */ |
| 5953 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | final long identity = Binder.clearCallingIdentity(); |
| 5955 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5956 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5957 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5958 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5959 | } finally { |
| 5960 | Binder.restoreCallingIdentity(identity); |
| 5961 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | /** |
| 5965 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5966 | */ |
| 5967 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | final long identity = Binder.clearCallingIdentity(); |
| 5969 | try { |
| 5970 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5971 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5972 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5973 | } finally { |
| 5974 | Binder.restoreCallingIdentity(identity); |
| 5975 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5976 | } |
| 5977 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5978 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5979 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5980 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5981 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5982 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5983 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5984 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5985 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5986 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5987 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5988 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5989 | } |
| 5990 | return PhoneFactory.getPhone(phoneId); |
| 5991 | } |
| 5992 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5993 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5994 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5995 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5996 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5997 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5998 | /*message=*/ "iccOpenLogicalChannel"); |
| 5999 | |
| 6000 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 6001 | // Verify that the callingPackage in the request belongs to the calling UID |
| 6002 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 6003 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6004 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6005 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 6006 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6007 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6008 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6009 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6010 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6011 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6012 | Phone phone; |
| 6013 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6015 | mApp, request.subId, message); |
| 6016 | phone = getPhoneFromSubId(request.subId); |
| 6017 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6018 | enforceModifyPermission(); |
| 6019 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6020 | } else { |
| 6021 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6022 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6023 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6024 | } |
| 6025 | |
| 6026 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6027 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6028 | final long identity = Binder.clearCallingIdentity(); |
| 6029 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6030 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6031 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6032 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6033 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6034 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6035 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | loge("The calling package is not allowed to access ISD-R."); |
| 6037 | throw new SecurityException( |
| 6038 | "The calling package is not allowed to access ISD-R."); |
| 6039 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6040 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6043 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6044 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6045 | return response; |
| 6046 | } finally { |
| 6047 | Binder.restoreCallingIdentity(identity); |
| 6048 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6052 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6053 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6054 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6055 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6056 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6057 | /*message=*/"iccCloseLogicalChannel"); |
| 6058 | |
| 6059 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6060 | |
| 6061 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6062 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6063 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6064 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6065 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6066 | // before this feature is enabled, this API should only return false if |
| 6067 | // the operation fails instead of throwing runtime exception for |
| 6068 | // backward-compatibility. |
| 6069 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6070 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6071 | final long identity = Binder.clearCallingIdentity(); |
| 6072 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6073 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6074 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6075 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6076 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6077 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6078 | Boolean success = false; |
| 6079 | if (result instanceof RuntimeException) { |
| 6080 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6081 | if (shouldThrowExceptionOnFailure) { |
| 6082 | throw (RuntimeException) result; |
| 6083 | } else { |
| 6084 | return false; |
| 6085 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6086 | } else if (result instanceof Boolean) { |
| 6087 | success = (Boolean) result; |
| 6088 | } else { |
| 6089 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6090 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6091 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6092 | return success; |
| 6093 | } finally { |
| 6094 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6095 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6099 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6100 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6102 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6103 | |
| 6104 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6105 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6106 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6107 | if (DBG) { |
| 6108 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6109 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6110 | + p3 + " data=" + data); |
| 6111 | } |
| 6112 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6113 | command, p1, p2, p3, data); |
| 6114 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6115 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6116 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6117 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6118 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6119 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6120 | |
| 6121 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6122 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6123 | "iccTransmitApduLogicalChannelBySlot"); |
| 6124 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6125 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6126 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6127 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6128 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6129 | } |
| 6130 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6131 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6132 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6136 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | final long identity = Binder.clearCallingIdentity(); |
| 6138 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6139 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | return ""; |
| 6141 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6144 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6145 | null /* workSource */); |
| 6146 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6147 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6148 | // Append the returned status code to the end of the response payload. |
| 6149 | String s = Integer.toHexString( |
| 6150 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6151 | if (response.payload != null) { |
| 6152 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6153 | } |
| 6154 | return s; |
| 6155 | } finally { |
| 6156 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6157 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6158 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6159 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6160 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6161 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6162 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6164 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6166 | |
| 6167 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6168 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6169 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6170 | if (DBG) { |
| 6171 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6172 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6173 | } |
| 6174 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6175 | cla, command, p1, p2, p3, data); |
| 6176 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6177 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6178 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6179 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6180 | 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] | 6181 | enforceModifyPermission(); |
| 6182 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6183 | |
| 6184 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6185 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6186 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6187 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6188 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6189 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6190 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6194 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6195 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6199 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6200 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6201 | final long identity = Binder.clearCallingIdentity(); |
| 6202 | try { |
| 6203 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6204 | && TextUtils.equals(ISDR_AID, data)) { |
| 6205 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6206 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6207 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 | if (bestComponent == null |
| 6209 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6210 | loge("The calling package is not allowed to select ISD-R."); |
| 6211 | throw new SecurityException( |
| 6212 | "The calling package is not allowed to select ISD-R."); |
| 6213 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6214 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6217 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6218 | null /* workSource */); |
| 6219 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6221 | // Append the returned status code to the end of the response payload. |
| 6222 | String s = Integer.toHexString( |
| 6223 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6224 | if (response.payload != null) { |
| 6225 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6226 | } |
| 6227 | return s; |
| 6228 | } finally { |
| 6229 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6230 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6234 | 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] | 6235 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6236 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6237 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6238 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6239 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6240 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | final long identity = Binder.clearCallingIdentity(); |
| 6243 | try { |
| 6244 | if (DBG) { |
| 6245 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6246 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6247 | } |
| 6248 | |
| 6249 | IccIoResult response = |
| 6250 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6251 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6252 | subId); |
| 6253 | |
| 6254 | if (DBG) { |
| 6255 | log("Exchange SIM_IO [R]" + response); |
| 6256 | } |
| 6257 | |
| 6258 | byte[] result = null; |
| 6259 | int length = 2; |
| 6260 | if (response.payload != null) { |
| 6261 | length = 2 + response.payload.length; |
| 6262 | result = new byte[length]; |
| 6263 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6264 | } else { |
| 6265 | result = new byte[length]; |
| 6266 | } |
| 6267 | |
| 6268 | result[length - 1] = (byte) response.sw2; |
| 6269 | result[length - 2] = (byte) response.sw1; |
| 6270 | return result; |
| 6271 | } finally { |
| 6272 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6273 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6274 | } |
| 6275 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6276 | /** |
| 6277 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6278 | * on a particular subscription |
| 6279 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6280 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6281 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6282 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6283 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6284 | return null; |
| 6285 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6287 | enforceTelephonyFeatureWithException(callingPackage, |
| 6288 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6289 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | final long identity = Binder.clearCallingIdentity(); |
| 6291 | try { |
| 6292 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6293 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6294 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6295 | return null; |
| 6296 | } |
| 6297 | Object response = sendRequest( |
| 6298 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6299 | if (response instanceof String[]) { |
| 6300 | return (String[]) response; |
| 6301 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6302 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6303 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6304 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6305 | } finally { |
| 6306 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6307 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6308 | } |
| 6309 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6310 | /** |
| 6311 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6312 | * subscription. |
| 6313 | * |
| 6314 | * @param subId the id of the subscription. |
| 6315 | * @param appType the uicc app type, must be USIM or SIM. |
| 6316 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6317 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6318 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6319 | * @return number of fplmns that is successfully written to the SIM. |
| 6320 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6321 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6322 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6324 | mApp, subId, "setForbiddenPlmns"); |
| 6325 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6326 | enforceTelephonyFeatureWithException(callingPackage, |
| 6327 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6328 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6329 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6330 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6331 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6332 | } |
| 6333 | if (fplmns == null) { |
| 6334 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6335 | } |
| 6336 | for (String fplmn : fplmns) { |
| 6337 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6338 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6339 | } |
| 6340 | } |
| 6341 | final long identity = Binder.clearCallingIdentity(); |
| 6342 | try { |
| 6343 | Object response = sendRequest( |
| 6344 | CMD_SET_FORBIDDEN_PLMNS, |
| 6345 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6346 | subId); |
| 6347 | return (int) response; |
| 6348 | } finally { |
| 6349 | Binder.restoreCallingIdentity(identity); |
| 6350 | } |
| 6351 | } |
| 6352 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6353 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6354 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6356 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6357 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6358 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6359 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6360 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
| 6363 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6364 | if (response.payload == null) { |
| 6365 | return ""; |
| 6366 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6367 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6368 | // Append the returned status code to the end of the response payload. |
| 6369 | String s = Integer.toHexString( |
| 6370 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6371 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6372 | return s; |
| 6373 | } finally { |
| 6374 | Binder.restoreCallingIdentity(identity); |
| 6375 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6376 | } |
| 6377 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6378 | /** |
| 6379 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6380 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6381 | * |
| 6382 | * @param itemID the ID of the item to read |
| 6383 | * @return the NV item as a String, or null on error. |
| 6384 | */ |
| 6385 | @Override |
| 6386 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6387 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6389 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | |
| 6391 | final long identity = Binder.clearCallingIdentity(); |
| 6392 | try { |
| 6393 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6394 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6395 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6396 | return value; |
| 6397 | } finally { |
| 6398 | Binder.restoreCallingIdentity(identity); |
| 6399 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | /** |
| 6403 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6404 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6405 | * |
| 6406 | * @param itemID the ID of the item to read |
| 6407 | * @param itemValue the value to write, as a String |
| 6408 | * @return true on success; false on any failure |
| 6409 | */ |
| 6410 | @Override |
| 6411 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6412 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6414 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | |
| 6416 | final long identity = Binder.clearCallingIdentity(); |
| 6417 | try { |
| 6418 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6419 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6420 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6422 | return success; |
| 6423 | } finally { |
| 6424 | Binder.restoreCallingIdentity(identity); |
| 6425 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | /** |
| 6429 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6430 | * Used for device configuration by some CDMA operators. |
| 6431 | * |
| 6432 | * @param preferredRoamingList byte array containing the new PRL |
| 6433 | * @return true on success; false on any failure |
| 6434 | */ |
| 6435 | @Override |
| 6436 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6437 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6438 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | |
| 6440 | final long identity = Binder.clearCallingIdentity(); |
| 6441 | try { |
| 6442 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6443 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6444 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6445 | return success; |
| 6446 | } finally { |
| 6447 | Binder.restoreCallingIdentity(identity); |
| 6448 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6449 | } |
| 6450 | |
| 6451 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6452 | * 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] | 6453 | * Used for device configuration by some CDMA operators. |
| 6454 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6455 | * @param slotIndex - device slot. |
| 6456 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6457 | * @return true on success; false on any failure |
| 6458 | */ |
| 6459 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6460 | public boolean resetModemConfig(int slotIndex) { |
| 6461 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6462 | if (phone != null) { |
| 6463 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6464 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6465 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6466 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6467 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6468 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6469 | final long identity = Binder.clearCallingIdentity(); |
| 6470 | try { |
| 6471 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6472 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6473 | return success; |
| 6474 | } finally { |
| 6475 | Binder.restoreCallingIdentity(identity); |
| 6476 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6477 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6478 | return false; |
| 6479 | } |
| 6480 | |
| 6481 | /** |
| 6482 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6483 | * |
| 6484 | * @param slotIndex - device slot. |
| 6485 | * |
| 6486 | * @return true on success; false on any failure |
| 6487 | */ |
| 6488 | @Override |
| 6489 | public boolean rebootModem(int slotIndex) { |
| 6490 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6491 | if (phone != null) { |
| 6492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6493 | mApp, phone.getSubId(), "rebootModem"); |
| 6494 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6495 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6496 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6497 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6498 | final long identity = Binder.clearCallingIdentity(); |
| 6499 | try { |
| 6500 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6501 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6502 | return success; |
| 6503 | } finally { |
| 6504 | Binder.restoreCallingIdentity(identity); |
| 6505 | } |
| 6506 | } |
| 6507 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6508 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6509 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6510 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6511 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6512 | * {@link #disableIms(int)}. |
| 6513 | * @param slotIndex device slot. |
| 6514 | */ |
| 6515 | public void resetIms(int slotIndex) { |
| 6516 | enforceModifyPermission(); |
| 6517 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6518 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6519 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6520 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6521 | final long identity = Binder.clearCallingIdentity(); |
| 6522 | try { |
| 6523 | if (mImsResolver == null) { |
| 6524 | // may happen if the does not support IMS. |
| 6525 | return; |
| 6526 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6527 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(identity); |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6534 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6535 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6536 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6537 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6538 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6539 | |
| 6540 | final long identity = Binder.clearCallingIdentity(); |
| 6541 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6542 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6543 | // may happen if the device does not support IMS. |
| 6544 | return; |
| 6545 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6546 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6547 | } finally { |
| 6548 | Binder.restoreCallingIdentity(identity); |
| 6549 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6550 | } |
| 6551 | |
| 6552 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6553 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6554 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6555 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6556 | public void disableIms(int slotId) { |
| 6557 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6558 | |
| 6559 | final long identity = Binder.clearCallingIdentity(); |
| 6560 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6561 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6562 | // may happen if the device does not support IMS. |
| 6563 | return; |
| 6564 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6565 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6566 | } finally { |
| 6567 | Binder.restoreCallingIdentity(identity); |
| 6568 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6572 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6573 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6574 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6575 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6576 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6577 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6578 | |
| 6579 | final long identity = Binder.clearCallingIdentity(); |
| 6580 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6581 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6582 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6583 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6584 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6585 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6586 | } finally { |
| 6587 | Binder.restoreCallingIdentity(identity); |
| 6588 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6589 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6590 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6591 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6592 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6593 | @Override |
| 6594 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6595 | enforceModifyPermission(); |
| 6596 | |
| 6597 | final long identity = Binder.clearCallingIdentity(); |
| 6598 | try { |
| 6599 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6600 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6601 | } finally { |
| 6602 | Binder.restoreCallingIdentity(identity); |
| 6603 | } |
| 6604 | } |
| 6605 | |
| 6606 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6607 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6608 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6609 | */ |
| 6610 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6611 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | |
| 6613 | final long identity = Binder.clearCallingIdentity(); |
| 6614 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6615 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6616 | // may happen if the device does not support IMS. |
| 6617 | return null; |
| 6618 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6619 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6620 | } finally { |
| 6621 | Binder.restoreCallingIdentity(identity); |
| 6622 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6623 | } |
| 6624 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6625 | /** |
| 6626 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6627 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6628 | */ |
| 6629 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6630 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6631 | |
| 6632 | final long identity = Binder.clearCallingIdentity(); |
| 6633 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6634 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6635 | // may happen if the device does not support IMS. |
| 6636 | return null; |
| 6637 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6638 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6639 | } finally { |
| 6640 | Binder.restoreCallingIdentity(identity); |
| 6641 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6642 | } |
| 6643 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6644 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6645 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6646 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6647 | * @param slotIndex the slot ID that the ImsService should bind for. |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6648 | * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL} |
| 6649 | * if there is no preference. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6650 | * @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] | 6651 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6652 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6653 | * @param packageName The name of the package that the current configuration will be replaced |
| 6654 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6655 | * @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] | 6656 | */ |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6657 | public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService, |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6658 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6659 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6661 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6662 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6663 | final long identity = Binder.clearCallingIdentity(); |
| 6664 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6665 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6666 | // may happen if the device does not support IMS. |
| 6667 | return false; |
| 6668 | } |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame] | 6669 | return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId, |
| 6670 | isCarrierService, featureTypes); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6671 | } finally { |
| 6672 | Binder.restoreCallingIdentity(identity); |
| 6673 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6677 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6678 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6679 | * |
| 6680 | * This should only be used for testing. |
| 6681 | * |
| 6682 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6683 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6684 | */ |
| 6685 | @Override |
| 6686 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6687 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6688 | "clearCarrierImsServiceOverride"); |
| 6689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6690 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6691 | |
| 6692 | final long identity = Binder.clearCallingIdentity(); |
| 6693 | try { |
| 6694 | if (mImsResolver == null) { |
| 6695 | // may happen if the device does not support IMS. |
| 6696 | return false; |
| 6697 | } |
| 6698 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6699 | } finally { |
| 6700 | Binder.restoreCallingIdentity(identity); |
| 6701 | } |
| 6702 | } |
| 6703 | |
| 6704 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6705 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6706 | * |
| 6707 | * @param slotId The slot that the ImsService is associated with. |
| 6708 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6709 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6710 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6711 | * @return the package name of the ImsService configuration. |
| 6712 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6713 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6714 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6715 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6716 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6717 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6718 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6719 | final long identity = Binder.clearCallingIdentity(); |
| 6720 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6721 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6722 | // may happen if the device does not support IMS. |
| 6723 | return ""; |
| 6724 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6725 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6726 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6727 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | } finally { |
| 6729 | Binder.restoreCallingIdentity(identity); |
| 6730 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6731 | } |
| 6732 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6733 | /** |
| 6734 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6735 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6736 | * @param callback A callback with an integer containing the |
| 6737 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6738 | */ |
| 6739 | @Override |
| 6740 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6741 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6742 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6743 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6744 | "IMS not available on device."); |
| 6745 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6746 | final long token = Binder.clearCallingIdentity(); |
| 6747 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6748 | int slotId = getSlotIndex(subId); |
| 6749 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6750 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6751 | + subId + "'"); |
| 6752 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6753 | } |
| 6754 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6755 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6756 | try { |
| 6757 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6758 | } catch (RemoteException e) { |
| 6759 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6760 | + "Ignore"); |
| 6761 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6762 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6763 | } catch (ImsException e) { |
| 6764 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(token); |
| 6767 | } |
| 6768 | } |
| 6769 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6770 | /** |
| 6771 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6772 | */ |
| 6773 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6774 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6775 | |
| 6776 | final long identity = Binder.clearCallingIdentity(); |
| 6777 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6778 | // NOTE: Before S, this method only set the default phone. |
| 6779 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6780 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6781 | phone.setImsRegistrationState(registered); |
| 6782 | } |
| 6783 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6784 | } finally { |
| 6785 | Binder.restoreCallingIdentity(identity); |
| 6786 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6790 | * Set the network selection mode to automatic. |
| 6791 | * |
| 6792 | */ |
| 6793 | @Override |
| 6794 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6796 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6797 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6798 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6799 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6800 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6801 | final long identity = Binder.clearCallingIdentity(); |
| 6802 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6803 | if (!isActiveSubscription(subId)) { |
| 6804 | return; |
| 6805 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6807 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 6808 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6809 | } finally { |
| 6810 | Binder.restoreCallingIdentity(identity); |
| 6811 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6812 | } |
| 6813 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6814 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6815 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6816 | * |
| 6817 | * @param subId the id of the subscription. |
| 6818 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6819 | * the operator to attach to. |
| 6820 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6821 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6822 | * normal network selection next time. |
| 6823 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6824 | */ |
| 6825 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6826 | public boolean setNetworkSelectionModeManual( |
| 6827 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6829 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6830 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6831 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6832 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6833 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6834 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6835 | if (!isActiveSubscription(subId)) { |
| 6836 | return false; |
| 6837 | } |
| 6838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6840 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6842 | if (DBG) { |
| 6843 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6844 | + " operator: " + operatorInfo); |
| 6845 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6846 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6847 | } finally { |
| 6848 | Binder.restoreCallingIdentity(identity); |
| 6849 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6850 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6851 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6852 | * Get the manual network selection |
| 6853 | * |
| 6854 | * @param subId the id of the subscription. |
| 6855 | * |
| 6856 | * @return the previously saved user selected PLMN |
| 6857 | */ |
| 6858 | @Override |
| 6859 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6860 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6861 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6862 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6863 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6864 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6865 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6866 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6867 | final long identity = Binder.clearCallingIdentity(); |
| 6868 | try { |
| 6869 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6870 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | final Phone phone = getPhone(subId); |
| 6874 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6875 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6876 | } |
| 6877 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6878 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6879 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6880 | } finally { |
| 6881 | Binder.restoreCallingIdentity(identity); |
| 6882 | } |
| 6883 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6884 | |
| 6885 | /** |
| 6886 | * Scans for available networks. |
| 6887 | */ |
| 6888 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6889 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6890 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6892 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6893 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6894 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6895 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6896 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6897 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6898 | .setCallingPid(Binder.getCallingPid()) |
| 6899 | .setCallingUid(Binder.getCallingUid()) |
| 6900 | .setMethod("getCellNetworkScanResults") |
| 6901 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6902 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6903 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6904 | .build()); |
| 6905 | switch (locationResult) { |
| 6906 | case DENIED_HARD: |
| 6907 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6908 | case DENIED_SOFT: |
| 6909 | return null; |
| 6910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6911 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6912 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6913 | try { |
| 6914 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6915 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6917 | } finally { |
| 6918 | Binder.restoreCallingIdentity(identity); |
| 6919 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6920 | } |
| 6921 | |
| 6922 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6923 | * Get the call forwarding info, given the call forwarding reason. |
| 6924 | */ |
| 6925 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6926 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6927 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6928 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6929 | |
| 6930 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6931 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6932 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6933 | long identity = Binder.clearCallingIdentity(); |
| 6934 | try { |
| 6935 | if (DBG) { |
| 6936 | log("getCallForwarding: subId " + subId |
| 6937 | + " callForwardingReason" + callForwardingReason); |
| 6938 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6939 | |
| 6940 | Phone phone = getPhone(subId); |
| 6941 | if (phone == null) { |
| 6942 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6943 | callback.onError( |
| 6944 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6945 | } catch (RemoteException e) { |
| 6946 | // ignore |
| 6947 | } |
| 6948 | return; |
| 6949 | } |
| 6950 | |
| 6951 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6952 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6953 | @Override |
| 6954 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6955 | try { |
| 6956 | callback.onCallForwardingInfoAvailable(info); |
| 6957 | } catch (RemoteException e) { |
| 6958 | // ignore |
| 6959 | } |
| 6960 | } |
| 6961 | |
| 6962 | @Override |
| 6963 | public void onError(int error) { |
| 6964 | try { |
| 6965 | callback.onError(error); |
| 6966 | } catch (RemoteException e) { |
| 6967 | // ignore |
| 6968 | } |
| 6969 | } |
| 6970 | }); |
| 6971 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6972 | } finally { |
| 6973 | Binder.restoreCallingIdentity(identity); |
| 6974 | } |
| 6975 | } |
| 6976 | |
| 6977 | /** |
| 6978 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6979 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6980 | */ |
| 6981 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6982 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6983 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6984 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6985 | |
| 6986 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6987 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6988 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6989 | long identity = Binder.clearCallingIdentity(); |
| 6990 | try { |
| 6991 | if (DBG) { |
| 6992 | log("setCallForwarding: subId " + subId |
| 6993 | + " callForwardingInfo" + callForwardingInfo); |
| 6994 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6995 | |
| 6996 | Phone phone = getPhone(subId); |
| 6997 | if (phone == null) { |
| 6998 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6999 | callback.accept( |
| 7000 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7001 | } catch (RemoteException e) { |
| 7002 | // ignore |
| 7003 | } |
| 7004 | return; |
| 7005 | } |
| 7006 | |
| 7007 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7008 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7009 | |
| 7010 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7011 | } finally { |
| 7012 | Binder.restoreCallingIdentity(identity); |
| 7013 | } |
| 7014 | } |
| 7015 | |
| 7016 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7017 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7018 | */ |
| 7019 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7020 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7021 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7022 | |
| 7023 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7024 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7025 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7026 | long identity = Binder.clearCallingIdentity(); |
| 7027 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7028 | Phone phone = getPhone(subId); |
| 7029 | if (phone == null) { |
| 7030 | try { |
| 7031 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7032 | } catch (RemoteException e) { |
| 7033 | // ignore |
| 7034 | } |
| 7035 | return; |
| 7036 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7037 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7038 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7039 | boolean requireUssd = c.getBoolean( |
| 7040 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7041 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7042 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7043 | if (requireUssd) { |
| 7044 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7045 | getSubscriptionCarrierId(subId)); |
| 7046 | String newUssdCommand = ""; |
| 7047 | try { |
| 7048 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7049 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7050 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7051 | } catch (NullPointerException e) { |
| 7052 | loge("Failed to generate USSD number" + e); |
| 7053 | } |
| 7054 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7055 | mMainThreadHandler, callback, carrierXmlParser, |
| 7056 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7057 | final String ussdCommand = newUssdCommand; |
| 7058 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7059 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7060 | }); |
| 7061 | } else { |
| 7062 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7063 | callback::accept); |
| 7064 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7065 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7066 | } finally { |
| 7067 | Binder.restoreCallingIdentity(identity); |
| 7068 | } |
| 7069 | } |
| 7070 | |
| 7071 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7072 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7073 | */ |
| 7074 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7075 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7076 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7077 | |
| 7078 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7079 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7080 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7081 | long identity = Binder.clearCallingIdentity(); |
| 7082 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7083 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7084 | |
| 7085 | Phone phone = getPhone(subId); |
| 7086 | if (phone == null) { |
| 7087 | try { |
| 7088 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7089 | } catch (RemoteException e) { |
| 7090 | // ignore |
| 7091 | } |
| 7092 | return; |
| 7093 | } |
| 7094 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7095 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7096 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7097 | boolean requireUssd = c.getBoolean( |
| 7098 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7099 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7100 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7101 | if (requireUssd) { |
| 7102 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7103 | getSubscriptionCarrierId(subId)); |
| 7104 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7105 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7106 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7107 | String newUssdCommand = ""; |
| 7108 | try { |
| 7109 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7110 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7111 | .makeCommand(ssAction, null); |
| 7112 | } catch (NullPointerException e) { |
| 7113 | loge("Failed to generate USSD number" + e); |
| 7114 | } |
| 7115 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7116 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7117 | final String ussdCommand = newUssdCommand; |
| 7118 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7119 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7120 | }); |
| 7121 | } else { |
| 7122 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7123 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7124 | |
| 7125 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7126 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7127 | } finally { |
| 7128 | Binder.restoreCallingIdentity(identity); |
| 7129 | } |
| 7130 | } |
| 7131 | |
| 7132 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7133 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7134 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7135 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7136 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7137 | * location related information which will be sent if the caller already possess |
| 7138 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7139 | * @param request contains the radio access networks with bands/channels to scan |
| 7140 | * @param messenger callback messenger for scan results or errors |
| 7141 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7142 | * @return the id of the requested scan which can be used to stop the scan. |
| 7143 | */ |
| 7144 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7145 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7146 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7147 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7149 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7150 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7151 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7152 | if (!renounceFineLocationAccess) { |
| 7153 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7154 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7155 | .setCallingPackage(callingPackage) |
| 7156 | .setCallingFeatureId(callingFeatureId) |
| 7157 | .setCallingPid(Binder.getCallingPid()) |
| 7158 | .setCallingUid(Binder.getCallingUid()) |
| 7159 | .setMethod("requestNetworkScan") |
| 7160 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7161 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7162 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7163 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7164 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7165 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7166 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7167 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7168 | if (e != null) { |
| 7169 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7170 | throw e; |
| 7171 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7172 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7173 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7174 | } |
| 7175 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7176 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7177 | |
| 7178 | enforceTelephonyFeatureWithException(callingPackage, |
| 7179 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7180 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7181 | int callingUid = Binder.getCallingUid(); |
| 7182 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7183 | final long identity = Binder.clearCallingIdentity(); |
| 7184 | try { |
| 7185 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7186 | renounceFineLocationAccess, request, messenger, binder, |
| 7187 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7188 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7189 | } finally { |
| 7190 | Binder.restoreCallingIdentity(identity); |
| 7191 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7192 | } |
| 7193 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7194 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7195 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7196 | boolean hasCarrierPriv; |
| 7197 | final long identity = Binder.clearCallingIdentity(); |
| 7198 | try { |
| 7199 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7200 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7201 | } finally { |
| 7202 | Binder.restoreCallingIdentity(identity); |
| 7203 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7204 | boolean hasNetworkScanPermission = |
| 7205 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7206 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7207 | |
| 7208 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7209 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7210 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7214 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7215 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7216 | return new SecurityException("Specific channels must not be" |
| 7217 | + " scanned without location access."); |
| 7218 | } |
| 7219 | } |
| 7220 | } |
| 7221 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7222 | return null; |
| 7223 | } |
| 7224 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7225 | /** |
| 7226 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7227 | * |
| 7228 | * @param subId id of the subscription |
| 7229 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7230 | */ |
| 7231 | @Override |
| 7232 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7234 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7236 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7237 | final long identity = Binder.clearCallingIdentity(); |
| 7238 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7239 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7240 | } finally { |
| 7241 | Binder.restoreCallingIdentity(identity); |
| 7242 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7243 | } |
| 7244 | |
| 7245 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7246 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7247 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7248 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7249 | */ |
| 7250 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7251 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7252 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7253 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7254 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7255 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7256 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7257 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7258 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7259 | final long identity = Binder.clearCallingIdentity(); |
| 7260 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7261 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7262 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7263 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7264 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7265 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7266 | } finally { |
| 7267 | Binder.restoreCallingIdentity(identity); |
| 7268 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7269 | } |
| 7270 | |
| 7271 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7272 | * Get the allowed network types for certain reason. |
| 7273 | * |
| 7274 | * @param subId the id of the subscription. |
| 7275 | * @param reason the reason the allowed network type change is taking place |
| 7276 | * @return the allowed network types. |
| 7277 | */ |
| 7278 | @Override |
| 7279 | public long getAllowedNetworkTypesForReason(int subId, |
| 7280 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7281 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7282 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7283 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7284 | if (!mApp.getResources().getBoolean( |
| 7285 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7286 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7287 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7288 | "getAllowedNetworkTypesForReason"); |
| 7289 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7290 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7293 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7294 | } finally { |
| 7295 | Binder.restoreCallingIdentity(identity); |
| 7296 | } |
| 7297 | } |
| 7298 | |
| 7299 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7300 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7301 | * @param subId subscription id of the sim card |
| 7302 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7303 | * This can be passed following states |
| 7304 | * <ol> |
| 7305 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7306 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7307 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7308 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7309 | * </ol> |
| 7310 | * @return operation result. |
| 7311 | */ |
| 7312 | @Override |
| 7313 | public int setNrDualConnectivityState(int subId, |
| 7314 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7315 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7316 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7317 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7318 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7319 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7320 | } |
| 7321 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7322 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7323 | final long identity = Binder.clearCallingIdentity(); |
| 7324 | try { |
| 7325 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7326 | nrDualConnectivityState, subId, |
| 7327 | workSource); |
| 7328 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7329 | return result; |
| 7330 | } finally { |
| 7331 | Binder.restoreCallingIdentity(identity); |
| 7332 | } |
| 7333 | } |
| 7334 | |
| 7335 | /** |
| 7336 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7337 | * @return true if dual connectivity is enabled else false |
| 7338 | */ |
| 7339 | @Override |
| 7340 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7341 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7342 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7343 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7344 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7345 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7346 | return false; |
| 7347 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7348 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7349 | final long identity = Binder.clearCallingIdentity(); |
| 7350 | try { |
| 7351 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7352 | null, subId, workSource); |
| 7353 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7354 | return isEnabled; |
| 7355 | } finally { |
| 7356 | Binder.restoreCallingIdentity(identity); |
| 7357 | } |
| 7358 | } |
| 7359 | |
| 7360 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7361 | * Set the allowed network types of the device and |
| 7362 | * provide the reason triggering the allowed network change. |
| 7363 | * |
| 7364 | * @param subId the id of the subscription. |
| 7365 | * @param reason the reason the allowed network type change is taking place |
| 7366 | * @param allowedNetworkTypes the allowed network types. |
| 7367 | * @return true on success; false on any failure. |
| 7368 | */ |
| 7369 | @Override |
| 7370 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7371 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7372 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7374 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7375 | // If the caller only has carrier privileges, then they should not be able to override |
| 7376 | // any network types which were set for security reasons. |
| 7377 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7378 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7379 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7380 | throw new SecurityException( |
| 7381 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7382 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7383 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7384 | |
| 7385 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7386 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7387 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7388 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7389 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7390 | return false; |
| 7391 | } |
| 7392 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7393 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7394 | return false; |
| 7395 | } |
| 7396 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7397 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7398 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7399 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7400 | Phone phone = getPhone(subId); |
| 7401 | if (phone == null) { |
| 7402 | return false; |
| 7403 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7404 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7405 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7406 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7407 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7408 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7409 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7410 | final long identity = Binder.clearCallingIdentity(); |
| 7411 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7412 | Boolean success = (Boolean) sendRequest( |
| 7413 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7414 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7415 | |
| 7416 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7417 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7418 | } finally { |
| 7419 | Binder.restoreCallingIdentity(identity); |
| 7420 | } |
| 7421 | } |
| 7422 | |
| 7423 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7424 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7425 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7426 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7427 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7428 | * @hide |
| 7429 | */ |
| 7430 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7431 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7432 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7433 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 7434 | if (!mApp.getResources().getBoolean( |
| 7435 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7436 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7437 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7438 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7439 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7440 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7441 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7442 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7443 | if (phone != null) { |
| 7444 | return phone.hasMatchedTetherApnSetting(); |
| 7445 | } else { |
| 7446 | return false; |
| 7447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7448 | } finally { |
| 7449 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7450 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7451 | } |
| 7452 | |
| 7453 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7454 | * Get the user enabled state of Mobile Data. |
| 7455 | * |
| 7456 | * TODO: remove and use isUserDataEnabled. |
| 7457 | * This can't be removed now because some vendor codes |
| 7458 | * calls through ITelephony directly while they should |
| 7459 | * use TelephonyManager. |
| 7460 | * |
| 7461 | * @return true on enabled |
| 7462 | */ |
| 7463 | @Override |
| 7464 | public boolean getDataEnabled(int subId) { |
| 7465 | return isUserDataEnabled(subId); |
| 7466 | } |
| 7467 | |
| 7468 | /** |
| 7469 | * Get whether mobile data is enabled per user setting. |
| 7470 | * |
| 7471 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7472 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7473 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7474 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7475 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7476 | * |
| 7477 | * @return {@code true} if data is enabled else {@code false} |
| 7478 | */ |
| 7479 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7480 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7481 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7482 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7483 | try { |
| 7484 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7485 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7486 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7487 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7488 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7489 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7490 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7491 | mApp, subId, functionName); |
| 7492 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7493 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7494 | |
| 7495 | final long identity = Binder.clearCallingIdentity(); |
| 7496 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7497 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7498 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7499 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7500 | if (phone != null) { |
| 7501 | boolean retVal = phone.isUserDataEnabled(); |
| 7502 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7503 | return retVal; |
| 7504 | } else { |
| 7505 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7506 | return false; |
| 7507 | } |
| 7508 | } finally { |
| 7509 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7510 | } |
| 7511 | } |
| 7512 | |
| 7513 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7514 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7515 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7516 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7517 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7518 | * @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] | 7519 | */ |
| 7520 | @Override |
| 7521 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7522 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7523 | try { |
| 7524 | try { |
| 7525 | mApp.enforceCallingOrSelfPermission( |
| 7526 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7527 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7528 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7529 | try { |
| 7530 | mApp.enforceCallingOrSelfPermission( |
| 7531 | android.Manifest.permission.READ_PHONE_STATE, |
| 7532 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7533 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7534 | mApp.enforceCallingOrSelfPermission( |
| 7535 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7536 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7537 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7538 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7539 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7540 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7542 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7543 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7544 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | final long identity = Binder.clearCallingIdentity(); |
| 7546 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7547 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7549 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7550 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7551 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7552 | return retVal; |
| 7553 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7554 | if (DBG) { |
| 7555 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7556 | + subId + " retVal=false"); |
| 7557 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7558 | return false; |
| 7559 | } |
| 7560 | } finally { |
| 7561 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7562 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7563 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7564 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7565 | /** |
| 7566 | * Check if data is enabled for a specific reason |
| 7567 | * @param subId Subscription index |
| 7568 | * @param reason the reason the data enable change is taking place |
| 7569 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7570 | */ |
| 7571 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7572 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7573 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7574 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7575 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7576 | try { |
| 7577 | mApp.enforceCallingOrSelfPermission( |
| 7578 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7579 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7580 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7581 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7582 | functionName); |
| 7583 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7584 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7585 | try { |
| 7586 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7587 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7588 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7590 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7591 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7592 | } |
| 7593 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7594 | if (!mApp.getResources().getBoolean( |
| 7595 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7596 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7597 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7598 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7599 | |
| 7600 | final long identity = Binder.clearCallingIdentity(); |
| 7601 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7602 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7603 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7604 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7605 | + " reason=" + reason); |
| 7606 | } |
| 7607 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7608 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7609 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7610 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7611 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7612 | return retVal; |
| 7613 | } else { |
| 7614 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7615 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7616 | + subId + " retVal=false"); |
| 7617 | } |
| 7618 | return false; |
| 7619 | } |
| 7620 | } finally { |
| 7621 | Binder.restoreCallingIdentity(identity); |
| 7622 | } |
| 7623 | } |
| 7624 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7625 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7626 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7627 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7628 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7629 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7630 | // No permission needed; this only lets the caller inspect their own status. |
| 7631 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7632 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7633 | |
| 7634 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7635 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7636 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7637 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7638 | if (!mApp.getResources().getBoolean( |
| 7639 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7640 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7641 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7642 | "getCarrierPrivilegeStatusForUid"); |
| 7643 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7644 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7645 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7646 | } |
| 7647 | |
| 7648 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7649 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7650 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7651 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7652 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7653 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7654 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7655 | if (cpt == null) { |
| 7656 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7657 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7658 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7659 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7663 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7664 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7665 | |
| 7666 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7667 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7668 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7669 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7670 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7671 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7672 | Phone phone = getPhone(subId); |
| 7673 | if (phone == null) { |
| 7674 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7675 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7676 | } |
| 7677 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7678 | if (cpt == null) { |
| 7679 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7680 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7681 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7682 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7683 | } |
| 7684 | |
| 7685 | @Override |
| 7686 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7687 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7688 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7689 | if (!mApp.getResources().getBoolean( |
| 7690 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7691 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7692 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7693 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7694 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7695 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7696 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7697 | } |
| 7698 | |
| 7699 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7700 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7701 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7702 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7703 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7704 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7705 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7706 | if (phone == null) { |
| 7707 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7708 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7709 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7710 | if (cpt == null) { |
| 7711 | continue; |
| 7712 | } |
| 7713 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7714 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7715 | break; |
| 7716 | } |
| 7717 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7718 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7719 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7720 | |
| 7721 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7722 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7723 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7724 | |
| 7725 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7726 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7727 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7728 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7729 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7730 | if (phone == null) { |
| 7731 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7732 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7733 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7734 | if (cpt == null) { |
| 7735 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7736 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7737 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7738 | } |
| 7739 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7740 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7741 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7742 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Yan Yan | 965c84f | 2024-09-24 18:14:17 -0700 | [diff] [blame] | 7743 | |
| 7744 | enforceTelephonyFeatureWithException( |
| 7745 | getCurrentPackageName(), |
| 7746 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7747 | "getPackagesWithCarrierPrivileges"); |
| 7748 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7749 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7750 | if (phone == null) { |
| 7751 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7752 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7753 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7754 | if (cpt == null) { |
| 7755 | return Collections.emptyList(); |
| 7756 | } |
| 7757 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7758 | } |
| 7759 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7760 | @Override |
| 7761 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7762 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7763 | |
| 7764 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7765 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7766 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7767 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7768 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7769 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7770 | try { |
| 7771 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7772 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7773 | } |
| 7774 | } finally { |
| 7775 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7776 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7777 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7778 | } |
| 7779 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7780 | @Override |
| 7781 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7782 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7783 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7784 | if (!mApp.getResources().getBoolean( |
| 7785 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7786 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7787 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7788 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7789 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7790 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7791 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7792 | if (phone == null) { |
| 7793 | return null; |
| 7794 | } |
| 7795 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7796 | if (cpt == null) { |
| 7797 | return null; |
| 7798 | } |
| 7799 | return cpt.getCarrierServicePackageName(); |
| 7800 | } |
| 7801 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7802 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7803 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7804 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7805 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7806 | return null; |
| 7807 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7808 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7809 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7810 | return null; |
| 7811 | } |
| 7812 | return iccId; |
| 7813 | } |
| 7814 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7815 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7816 | public void setCallComposerStatus(int subId, int status) { |
| 7817 | enforceModifyPermission(); |
| 7818 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7819 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7820 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7821 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7822 | final long identity = Binder.clearCallingIdentity(); |
| 7823 | try { |
| 7824 | Phone phone = getPhone(subId); |
| 7825 | if (phone != null) { |
| 7826 | Phone defaultPhone = phone.getImsPhone(); |
| 7827 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7828 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7829 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7830 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7831 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7832 | } |
| 7833 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7834 | } catch (ImsException e) { |
| 7835 | throw new ServiceSpecificException(e.getCode()); |
| 7836 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7837 | Binder.restoreCallingIdentity(identity); |
| 7838 | } |
| 7839 | } |
| 7840 | |
| 7841 | @Override |
| 7842 | public int getCallComposerStatus(int subId) { |
| 7843 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7844 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7845 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7846 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7847 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7848 | final long identity = Binder.clearCallingIdentity(); |
| 7849 | try { |
| 7850 | Phone phone = getPhone(subId); |
| 7851 | if (phone != null) { |
| 7852 | Phone defaultPhone = phone.getImsPhone(); |
| 7853 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7854 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7855 | return imsPhone.getCallComposerStatus(); |
| 7856 | } |
| 7857 | } |
| 7858 | } finally { |
| 7859 | Binder.restoreCallingIdentity(identity); |
| 7860 | } |
| 7861 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7862 | } |
| 7863 | |
| 7864 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7865 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7866 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7867 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7868 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7869 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7870 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7871 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7872 | "setLine1NumberForDisplayForSubscriber"); |
| 7873 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7874 | final long identity = Binder.clearCallingIdentity(); |
| 7875 | try { |
| 7876 | final String iccId = getIccId(subId); |
| 7877 | final Phone phone = getPhone(subId); |
| 7878 | if (phone == null) { |
| 7879 | return false; |
| 7880 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 7881 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7882 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7883 | return false; |
| 7884 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7885 | final String subscriberId = phone.getSubscriberId(); |
| 7886 | |
| 7887 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7888 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7889 | + subscriberId + " to " + number); |
| 7890 | } |
| 7891 | |
| 7892 | if (TextUtils.isEmpty(iccId)) { |
| 7893 | return false; |
| 7894 | } |
| 7895 | |
| 7896 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7897 | |
| 7898 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7899 | if (alphaTag == null) { |
| 7900 | editor.remove(alphaTagPrefKey); |
| 7901 | } else { |
| 7902 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7903 | } |
| 7904 | |
| 7905 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7906 | // track all merged IMSIs based on line number |
| 7907 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7908 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7909 | if (number == null) { |
| 7910 | editor.remove(numberPrefKey); |
| 7911 | editor.remove(subscriberPrefKey); |
| 7912 | } else { |
| 7913 | editor.putString(numberPrefKey, number); |
| 7914 | editor.putString(subscriberPrefKey, subscriberId); |
| 7915 | } |
| 7916 | |
| 7917 | editor.commit(); |
| 7918 | return true; |
| 7919 | } finally { |
| 7920 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7921 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7922 | } |
| 7923 | |
| 7924 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7925 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7926 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7927 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7928 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7929 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7930 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7931 | return null; |
| 7932 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7933 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7934 | if (!mApp.getResources().getBoolean( |
| 7935 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7936 | enforceTelephonyFeatureWithException(callingPackage, |
| 7937 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7938 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7939 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7940 | final long identity = Binder.clearCallingIdentity(); |
| 7941 | try { |
| 7942 | String iccId = getIccId(subId); |
| 7943 | if (iccId != null) { |
| 7944 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7945 | if (DBG_MERGE) { |
| 7946 | log("getLine1NumberForDisplay returning " |
| 7947 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7948 | } |
| 7949 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7950 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7951 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7952 | return null; |
| 7953 | } finally { |
| 7954 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7955 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7956 | } |
| 7957 | |
| 7958 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7959 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7960 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7961 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7962 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7963 | return null; |
| 7964 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7965 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7966 | final long identity = Binder.clearCallingIdentity(); |
| 7967 | try { |
| 7968 | String iccId = getIccId(subId); |
| 7969 | if (iccId != null) { |
| 7970 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7971 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7972 | } |
| 7973 | return null; |
| 7974 | } finally { |
| 7975 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7976 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7977 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7978 | |
| 7979 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7980 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7981 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7982 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7983 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7984 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7985 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7986 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7987 | return null; |
| 7988 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7989 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7990 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7991 | // the process, where TelephonyManager was instantiated. |
| 7992 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7993 | final long identity = Binder.clearCallingIdentity(); |
| 7994 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7995 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7996 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7997 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7998 | |
| 7999 | // Figure out what subscribers are currently active |
| 8000 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8001 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 8002 | // Only consider subs which match the current subId |
| 8003 | // This logic can be simplified. See b/131189269 for progress. |
| 8004 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8005 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 8006 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8007 | |
| 8008 | // First pass, find a number override for an active subscriber |
| 8009 | String mergeNumber = null; |
| 8010 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 8011 | for (String key : prefs.keySet()) { |
| 8012 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 8013 | final String subscriberId = (String) prefs.get(key); |
| 8014 | if (activeSubscriberIds.contains(subscriberId)) { |
| 8015 | final String iccId = key.substring( |
| 8016 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 8017 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8018 | mergeNumber = (String) prefs.get(numberKey); |
| 8019 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8020 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8021 | + " for active subscriber " + subscriberId); |
| 8022 | } |
| 8023 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8024 | break; |
| 8025 | } |
| 8026 | } |
| 8027 | } |
| 8028 | } |
| 8029 | |
| 8030 | // Shortcut when no active merged subscribers |
| 8031 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8032 | return null; |
| 8033 | } |
| 8034 | |
| 8035 | // Second pass, find all subscribers under that line override |
| 8036 | final ArraySet<String> result = new ArraySet<>(); |
| 8037 | for (String key : prefs.keySet()) { |
| 8038 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8039 | final String number = (String) prefs.get(key); |
| 8040 | if (mergeNumber.equals(number)) { |
| 8041 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8042 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8043 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8044 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8045 | result.add(subscriberId); |
| 8046 | } |
| 8047 | } |
| 8048 | } |
| 8049 | } |
| 8050 | |
| 8051 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8052 | Arrays.sort(resultArray); |
| 8053 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8054 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8055 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8056 | } |
| 8057 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8058 | } finally { |
| 8059 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8060 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8061 | } |
| 8062 | |
| 8063 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8064 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8065 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8066 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8067 | enforceTelephonyFeatureWithException(callingPackage, |
| 8068 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8069 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8070 | final long identity = Binder.clearCallingIdentity(); |
| 8071 | try { |
| 8072 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8073 | TelephonyManager.class); |
| 8074 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8075 | if (subscriberId == null) { |
| 8076 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8077 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8078 | + subId); |
| 8079 | } |
| 8080 | return null; |
| 8081 | } |
| 8082 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8083 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8084 | .getSubscriptionInfo(subId); |
| 8085 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8086 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8087 | if (groupUuid == null) { |
| 8088 | return new String[]{subscriberId}; |
| 8089 | } |
| 8090 | |
| 8091 | // Get all subscriberIds from the group. |
| 8092 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8093 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8094 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8095 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8096 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8097 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8098 | if (subscriberId != null) { |
| 8099 | mergedSubscriberIds.add(subscriberId); |
| 8100 | } |
| 8101 | } |
| 8102 | |
| 8103 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8104 | } finally { |
| 8105 | Binder.restoreCallingIdentity(identity); |
| 8106 | |
| 8107 | } |
| 8108 | } |
| 8109 | |
| 8110 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8111 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8112 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8113 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8115 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8116 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8117 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8118 | final long identity = Binder.clearCallingIdentity(); |
| 8119 | try { |
| 8120 | final Phone phone = getPhone(subId); |
| 8121 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
| 8124 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8125 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8126 | |
| 8127 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8128 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8129 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8130 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8131 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8132 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8133 | |
| 8134 | final long identity = Binder.clearCallingIdentity(); |
| 8135 | try { |
| 8136 | final Phone phone = getPhone(subId); |
| 8137 | if (phone == null) { |
| 8138 | return false; |
| 8139 | } |
| 8140 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8141 | cdmaNonRoamingList); |
| 8142 | } finally { |
| 8143 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8144 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8145 | } |
| 8146 | |
| 8147 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8148 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8149 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8150 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8151 | if (phone == null) { |
| 8152 | return raf; |
| 8153 | } |
| 8154 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8155 | try { |
| 8156 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8157 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8158 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8159 | } catch (SecurityException e) { |
| 8160 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8161 | throw e; |
| 8162 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8163 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8164 | if (!mApp.getResources().getBoolean( |
| 8165 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8166 | enforceTelephonyFeatureWithException(callingPackage, |
| 8167 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8168 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8169 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8170 | final long identity = Binder.clearCallingIdentity(); |
| 8171 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8172 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8173 | } finally { |
| 8174 | Binder.restoreCallingIdentity(identity); |
| 8175 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8176 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8177 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8178 | |
| 8179 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8180 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8181 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8182 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8183 | "Invalid package:" + callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8184 | enforceTelephonyFeatureWithException(callingPackage, |
| 8185 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8186 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8187 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8188 | List<String> dialerRoleHolders; |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8189 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8190 | UserHandle.of(ActivityManager.getCurrentUser())); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8191 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8192 | throw new SecurityException("App must be the dialer role holder to" |
| 8193 | + " upload a call composer pic"); |
| 8194 | } |
| 8195 | |
| 8196 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8197 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8198 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8199 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8200 | boolean readUntilEnd = false; |
| 8201 | int totalBytesRead = 0; |
| 8202 | byte[] buffer = new byte[16 * 1024]; |
| 8203 | while (true) { |
| 8204 | int numRead; |
| 8205 | try { |
| 8206 | numRead = input.read(buffer); |
| 8207 | } catch (IOException e) { |
| 8208 | try { |
| 8209 | fd.checkError(); |
| 8210 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8211 | null); |
| 8212 | } catch (IOException e1) { |
| 8213 | // This means that the other side closed explicitly with an error. If this |
| 8214 | // happens, log and ignore. |
| 8215 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8216 | } |
| 8217 | break; |
| 8218 | } |
| 8219 | if (numRead == -1) { |
| 8220 | readUntilEnd = true; |
| 8221 | break; |
| 8222 | } |
| 8223 | totalBytesRead += numRead; |
| 8224 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8225 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8226 | try { |
| 8227 | input.close(); |
| 8228 | } catch (IOException e) { |
| 8229 | // ignore |
| 8230 | } |
| 8231 | break; |
| 8232 | } |
| 8233 | output.write(buffer, 0, numRead); |
| 8234 | } |
| 8235 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8236 | // close is above, where the picture size is too big. |
| 8237 | |
| 8238 | try { |
| 8239 | fd.checkError(); |
| 8240 | } catch (IOException e) { |
| 8241 | loge("Remote end for call composer closed with an error: " + e); |
| 8242 | return; |
| 8243 | } |
| 8244 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8245 | if (!readUntilEnd) { |
| 8246 | loge("Did not finish reading entire image; aborting"); |
| 8247 | return; |
| 8248 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8249 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8250 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8251 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8252 | new CallComposerPictureTransfer.Factory() {}, |
| 8253 | imageData, |
| 8254 | (result) -> { |
| 8255 | if (result.first != null) { |
| 8256 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8257 | Bundle outputResult = new Bundle(); |
| 8258 | outputResult.putParcelable( |
| 8259 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8260 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8261 | outputResult); |
| 8262 | } else { |
| 8263 | callback.send(result.second, null); |
| 8264 | } |
| 8265 | } |
| 8266 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8267 | }); |
| 8268 | } |
| 8269 | |
| 8270 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8271 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8272 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8273 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8274 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8275 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8276 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8277 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8278 | final long identity = Binder.clearCallingIdentity(); |
| 8279 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8280 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8281 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8282 | } finally { |
| 8283 | Binder.restoreCallingIdentity(identity); |
| 8284 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8285 | } |
| 8286 | |
| 8287 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8288 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8289 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8290 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8291 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8292 | return false; |
| 8293 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8294 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8295 | enforceTelephonyFeatureWithException(callingPackage, |
| 8296 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8298 | final long identity = Binder.clearCallingIdentity(); |
| 8299 | try { |
| 8300 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8301 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8302 | // In the long run, we may instead need to check if there exists a connection service |
| 8303 | // which can support video calling. |
| 8304 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8305 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8306 | return imsManager.isVtEnabledByPlatform() |
| 8307 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8308 | && imsManager.isVtEnabledByUser(); |
| 8309 | } finally { |
| 8310 | Binder.restoreCallingIdentity(identity); |
| 8311 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8312 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8313 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8314 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8315 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8316 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8317 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8318 | mApp, subId, callingPackage, callingFeatureId, |
| 8319 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8320 | return false; |
| 8321 | } |
| 8322 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8323 | enforceTelephonyFeatureWithException(callingPackage, |
| 8324 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8325 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8326 | final long identity = Binder.clearCallingIdentity(); |
| 8327 | try { |
| 8328 | CarrierConfigManager configManager = |
| 8329 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8330 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8331 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8332 | } finally { |
| 8333 | Binder.restoreCallingIdentity(identity); |
| 8334 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8335 | } |
| 8336 | |
| 8337 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8338 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8339 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8340 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8341 | return false; |
| 8342 | } |
| 8343 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8344 | enforceTelephonyFeatureWithException(callingPackage, |
| 8345 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8346 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8347 | final long identity = Binder.clearCallingIdentity(); |
| 8348 | try { |
| 8349 | CarrierConfigManager configManager = |
| 8350 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8351 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8352 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8353 | } finally { |
| 8354 | Binder.restoreCallingIdentity(identity); |
| 8355 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8356 | } |
| 8357 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8358 | @Override |
| 8359 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8360 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8361 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8362 | } |
| 8363 | |
| 8364 | @Override |
| 8365 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8366 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8367 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8369 | final long identity = Binder.clearCallingIdentity(); |
| 8370 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8371 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
| 8374 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8375 | } |
| 8376 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8377 | /** |
| 8378 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8379 | * support for the feature and device firmware support. |
| 8380 | * |
| 8381 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8382 | */ |
| 8383 | @Override |
| 8384 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8385 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8386 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8387 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8388 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8389 | final Phone phone = getPhone(subscriptionId); |
| 8390 | if (phone == null) { |
| 8391 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8392 | return false; |
| 8393 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8394 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8395 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8396 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8397 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8398 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8399 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8400 | return isCarrierSupported && isDeviceSupported; |
| 8401 | } finally { |
| 8402 | Binder.restoreCallingIdentity(identity); |
| 8403 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8404 | } |
| 8405 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8406 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8407 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8408 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8409 | * 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] | 8410 | */ |
| 8411 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8412 | final long identity = Binder.clearCallingIdentity(); |
| 8413 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8414 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8415 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8416 | return false; |
| 8417 | } |
| 8418 | } |
| 8419 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8420 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8421 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8422 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8423 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8424 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8425 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8426 | } finally { |
| 8427 | Binder.restoreCallingIdentity(identity); |
| 8428 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8429 | } |
| 8430 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8431 | @Deprecated |
| 8432 | @Override |
| 8433 | public String getDeviceId(String callingPackage) { |
| 8434 | return getDeviceIdWithFeature(callingPackage, null); |
| 8435 | } |
| 8436 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8437 | /** |
| 8438 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8439 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8440 | * |
| 8441 | * <p>Requires Permission: |
| 8442 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8443 | */ |
| 8444 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8445 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8446 | try { |
| 8447 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8448 | } catch (SecurityException se) { |
| 8449 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8450 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8451 | + Binder.getCallingUid()); |
| 8452 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8453 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8454 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8455 | return null; |
| 8456 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8457 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8458 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8459 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8460 | return null; |
| 8461 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8462 | |
| 8463 | final long identity = Binder.clearCallingIdentity(); |
| 8464 | try { |
| 8465 | return phone.getDeviceId(); |
| 8466 | } finally { |
| 8467 | Binder.restoreCallingIdentity(identity); |
| 8468 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8469 | } |
| 8470 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8471 | /** |
| 8472 | * {@hide} |
| 8473 | * Returns the IMS Registration Status on a particular subid |
| 8474 | * |
| 8475 | * @param subId |
| 8476 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8477 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8478 | Phone phone = getPhone(subId); |
| 8479 | if (phone != null) { |
| 8480 | return phone.isImsRegistered(); |
| 8481 | } else { |
| 8482 | return false; |
| 8483 | } |
| 8484 | } |
| 8485 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8486 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8487 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8488 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8489 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8490 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8491 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8492 | } |
| 8493 | final long identity = Binder.clearCallingIdentity(); |
| 8494 | try { |
| 8495 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8496 | } finally { |
| 8497 | Binder.restoreCallingIdentity(identity); |
| 8498 | } |
| 8499 | } |
| 8500 | |
| 8501 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8502 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8503 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8504 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8505 | mApp, |
| 8506 | subscriptionId, |
| 8507 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8508 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8509 | |
| 8510 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8511 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8512 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8513 | final long identity = Binder.clearCallingIdentity(); |
| 8514 | try { |
| 8515 | Phone phone = getPhone(subscriptionId); |
| 8516 | if (phone == null) { |
| 8517 | return null; |
| 8518 | } |
| 8519 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8520 | } finally { |
| 8521 | Binder.restoreCallingIdentity(identity); |
| 8522 | } |
| 8523 | } |
| 8524 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8525 | /** |
| 8526 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8527 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8528 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8529 | final long identity = Binder.clearCallingIdentity(); |
| 8530 | try { |
| 8531 | Phone phone = getPhone(subId); |
| 8532 | if (phone != null) { |
| 8533 | return phone.isWifiCallingEnabled(); |
| 8534 | } else { |
| 8535 | return false; |
| 8536 | } |
| 8537 | } finally { |
| 8538 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8539 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8540 | } |
| 8541 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8542 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8543 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8544 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8545 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8546 | final long identity = Binder.clearCallingIdentity(); |
| 8547 | try { |
| 8548 | Phone phone = getPhone(subId); |
| 8549 | if (phone != null) { |
| 8550 | return phone.isVideoEnabled(); |
| 8551 | } else { |
| 8552 | return false; |
| 8553 | } |
| 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8556 | } |
| 8557 | } |
| 8558 | |
| 8559 | /** |
| 8560 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8561 | * defined in {@link ImsRegistrationImplBase}. |
| 8562 | */ |
| 8563 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8564 | final long identity = Binder.clearCallingIdentity(); |
| 8565 | try { |
| 8566 | Phone phone = getPhone(subId); |
| 8567 | if (phone != null) { |
| 8568 | return phone.getImsRegistrationTech(); |
| 8569 | } else { |
| 8570 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8571 | } |
| 8572 | } finally { |
| 8573 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8574 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8575 | } |
| 8576 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8577 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8578 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8579 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8580 | |
| 8581 | enforceTelephonyFeatureWithException(callingPackage, |
| 8582 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8583 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8584 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8585 | return; |
| 8586 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8587 | Phone defaultPhone = getDefaultPhone(); |
| 8588 | if (defaultPhone != null) { |
| 8589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8590 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8591 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8592 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8593 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8594 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8595 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8596 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8597 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8598 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8599 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8600 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8601 | cleanUpAllowedNetworkTypes(phone, subId); |
TAKAHASHI Uichiro | c4b0745 | 2022-08-29 16:03:11 +0900 | [diff] [blame] | 8602 | |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8603 | setDataRoamingEnabled(subId, phone == null ? false |
| 8604 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
TAKAHASHI Uichiro | c4b0745 | 2022-08-29 16:03:11 +0900 | [diff] [blame] | 8605 | getPhone(subId).resetCarrierKeysForImsiEncryption(true); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8606 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8607 | // There has been issues when Sms raw table somehow stores orphan |
| 8608 | // fragments. They lead to garbled message when new fragments come |
| 8609 | // in and combined with those stale ones. In case this happens again, |
| 8610 | // user can reset all network settings which will clean up this table. |
| 8611 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8612 | // Clean up IMS settings as well here. |
| 8613 | int slotId = getSlotIndex(subId); |
Tomasz Wasilczyk | 2159ca2 | 2024-07-25 13:54:35 -0700 | [diff] [blame] | 8614 | if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8615 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8616 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8617 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8618 | if (defaultPhone == null) { |
| 8619 | return; |
| 8620 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8621 | // Erase modem config if erase modem on network setting is enabled. |
| 8622 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8623 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8624 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8625 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8626 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8627 | |
| 8628 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8629 | } finally { |
| 8630 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8631 | } |
| 8632 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8633 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8634 | @VisibleForTesting |
| 8635 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8636 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8637 | return; |
| 8638 | } |
| 8639 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8640 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8641 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8642 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8643 | "user=" + defaultNetworkType); |
| 8644 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8645 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8646 | defaultNetworkType, null); |
| 8647 | } |
| 8648 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8649 | private void cleanUpSmsRawTable(Context context) { |
| 8650 | ContentResolver resolver = context.getContentResolver(); |
| 8651 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8652 | resolver.delete(uri, null, null); |
| 8653 | } |
| 8654 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8655 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8656 | public String getSimLocaleForSubscriber(int subId) { |
| 8657 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8658 | |
| 8659 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8660 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8661 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8662 | final Phone phone = getPhone(subId); |
| 8663 | if (phone == null) { |
| 8664 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8665 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8667 | final long identity = Binder.clearCallingIdentity(); |
| 8668 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8669 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8670 | phone.getContext().getOpPackageName(), |
| 8671 | phone.getContext().getAttributionTag()); |
| 8672 | if (info == null) { |
| 8673 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8674 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8675 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8676 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8677 | // preferences (EF-PL and EF-LI)... |
| 8678 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8679 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8680 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8681 | if (localeFromDefaultSim != null) { |
| 8682 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8683 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8684 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8685 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8686 | } else { |
| 8687 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8688 | } |
| 8689 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8690 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8691 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8692 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8693 | // the SIM and carrier preferences does not include a country we add the country |
| 8694 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8695 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8696 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8697 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8698 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8699 | } |
| 8700 | |
| 8701 | if (DBG) log("No locale found - returning null"); |
| 8702 | return null; |
| 8703 | } finally { |
| 8704 | Binder.restoreCallingIdentity(identity); |
| 8705 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8706 | } |
| 8707 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8708 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8709 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8710 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8711 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8712 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8713 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8714 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8715 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8716 | return localeTag; |
| 8717 | } |
| 8718 | } |
| 8719 | return inputLocale.toLanguageTag(); |
| 8720 | } |
| 8721 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8722 | /** |
| 8723 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8724 | */ |
| 8725 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8726 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8727 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8728 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8729 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8730 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8731 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8732 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8733 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8734 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8735 | * representing the state of the modem. |
| 8736 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8737 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8738 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8739 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8740 | */ |
| 8741 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8742 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8743 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8744 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 8745 | if (!mApp.getResources().getBoolean( |
| 8746 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8747 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8748 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8749 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8750 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8751 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8752 | |
| 8753 | final long identity = Binder.clearCallingIdentity(); |
| 8754 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8755 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8756 | } finally { |
| 8757 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8758 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8759 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8760 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8761 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8762 | // less than total activity duration. |
| 8763 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8764 | if (info == null) { |
| 8765 | return false; |
| 8766 | } |
| 8767 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8768 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8769 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8770 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8771 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8772 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8773 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8774 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8775 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8776 | } |
| 8777 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8778 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8779 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8780 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8781 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8782 | |
| 8783 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8784 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8785 | } |
| 8786 | |
| 8787 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8788 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8789 | rat, |
| 8790 | freq, |
| 8791 | info.getReceiveTimeMillis(rat, freq) |
| 8792 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8793 | } |
| 8794 | |
| 8795 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8796 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8797 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8798 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8799 | |
| 8800 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8801 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8802 | } |
| 8803 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8804 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8805 | rat, |
| 8806 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8807 | } |
| 8808 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8809 | /** |
| 8810 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8811 | * @param info recent ModemActivityInfo |
| 8812 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8813 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8814 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8815 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8816 | boolean matched; |
| 8817 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8818 | matched = false; |
| 8819 | int rat = info.getSpecificInfoRat(i); |
| 8820 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8821 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8822 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8823 | //if it already exists |
| 8824 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8825 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8826 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8827 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8828 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8829 | updateLastModemActivityInfo(info, rat, freq); |
| 8830 | matched = true; |
| 8831 | } |
| 8832 | } else { |
| 8833 | updateLastModemActivityInfo(info, rat); |
| 8834 | matched = true; |
| 8835 | } |
| 8836 | } |
| 8837 | } |
| 8838 | |
| 8839 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8840 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8841 | new ActivityStatsTechSpecificInfo( |
| 8842 | rat, |
| 8843 | freq, |
| 8844 | info.getTransmitTimeMillis(rat, freq), |
| 8845 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8846 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8847 | } |
| 8848 | } |
| 8849 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8850 | mLastModemActivitySpecificInfo = |
| 8851 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8852 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8853 | |
| 8854 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8855 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8856 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8857 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8858 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8859 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8860 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8861 | |
| 8862 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8863 | new ModemActivityInfo( |
| 8864 | mLastModemActivityInfo.getTimestampMillis(), |
| 8865 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8866 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8867 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8868 | } |
| 8869 | |
| 8870 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8871 | ActivityStatsTechSpecificInfo[] info) { |
| 8872 | int infoSize = info.length; |
| 8873 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8874 | for (int i = 0; i < infoSize; i++) { |
| 8875 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8876 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8877 | info[i].getTransmitTimeMillis(), |
| 8878 | (int) info[i].getReceiveTimeMillis()); |
| 8879 | } |
| 8880 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8881 | } |
| 8882 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8883 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8884 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8885 | */ |
| 8886 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8887 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8888 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8889 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8890 | if (phone == null) { |
| 8891 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8892 | return null; |
| 8893 | } |
| 8894 | |
| 8895 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8896 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8897 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8898 | return null; |
| 8899 | } |
| 8900 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8901 | enforceTelephonyFeatureWithException(callingPackage, |
| 8902 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8903 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8904 | boolean hasFinePermission = false; |
| 8905 | boolean hasCoarsePermission = false; |
| 8906 | if (!renounceFineLocationAccess) { |
| 8907 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8908 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8909 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8910 | .setCallingPackage(callingPackage) |
| 8911 | .setCallingFeatureId(callingFeatureId) |
| 8912 | .setCallingPid(Binder.getCallingPid()) |
| 8913 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8914 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8915 | .setLogAsInfo(true) |
| 8916 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8917 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8918 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8919 | .build()); |
| 8920 | hasFinePermission = |
| 8921 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8922 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8923 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8924 | if (!renounceCoarseLocationAccess) { |
| 8925 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8926 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8927 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8928 | .setCallingPackage(callingPackage) |
| 8929 | .setCallingFeatureId(callingFeatureId) |
| 8930 | .setCallingPid(Binder.getCallingPid()) |
| 8931 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8932 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8933 | .setLogAsInfo(true) |
| 8934 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8935 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8936 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8937 | .build()); |
| 8938 | hasCoarsePermission = |
| 8939 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8940 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8941 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8942 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8943 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8944 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8945 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8946 | if (subInfo != null && !subInfo.isActive()) { |
| 8947 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8948 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8949 | } |
| 8950 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8951 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8952 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8953 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8954 | |
| 8955 | // Scrub out the location info in ServiceState depending on what level of access |
| 8956 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8957 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8958 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8959 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8960 | } finally { |
| 8961 | Binder.restoreCallingIdentity(identity); |
| 8962 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8963 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8964 | |
| 8965 | /** |
| 8966 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8967 | * |
| 8968 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8969 | * voicemail ringtone. |
| 8970 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8971 | * PhoneAccount. |
| 8972 | */ |
| 8973 | @Override |
| 8974 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8975 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8976 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8977 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | final long identity = Binder.clearCallingIdentity(); |
| 8979 | try { |
| 8980 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8981 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8982 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8983 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8985 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8986 | } finally { |
| 8987 | Binder.restoreCallingIdentity(identity); |
| 8988 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8989 | } |
| 8990 | |
| 8991 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8992 | * Sets the per-account voicemail ringtone. |
| 8993 | * |
| 8994 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8995 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8996 | * |
| 8997 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8998 | * voicemail ringtone. |
| 8999 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 9000 | * PhoneAccount. |
| 9001 | */ |
| 9002 | @Override |
| 9003 | public void setVoicemailRingtoneUri(String callingPackage, |
| 9004 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9005 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9006 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9007 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9008 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9010 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9011 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9012 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9013 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9014 | enforceTelephonyFeatureWithException(callingPackage, |
| 9015 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9017 | final long identity = Binder.clearCallingIdentity(); |
| 9018 | try { |
| 9019 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9020 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9021 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9022 | } |
| 9023 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9024 | } finally { |
| 9025 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9026 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9027 | } |
| 9028 | |
| 9029 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9030 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9031 | * |
| 9032 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9033 | * voicemail vibration setting. |
| 9034 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9035 | */ |
| 9036 | @Override |
| 9037 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9038 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9039 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9041 | final long identity = Binder.clearCallingIdentity(); |
| 9042 | try { |
| 9043 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9044 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9045 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9046 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9048 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9049 | } finally { |
| 9050 | Binder.restoreCallingIdentity(identity); |
| 9051 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9052 | } |
| 9053 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9054 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9055 | * Sets the per-account voicemail vibration. |
| 9056 | * |
| 9057 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9058 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9059 | * |
| 9060 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9061 | * voicemail vibration setting. |
| 9062 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9063 | * specific PhoneAccount. |
| 9064 | */ |
| 9065 | @Override |
| 9066 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9067 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9068 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9069 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9070 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9071 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9073 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9074 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9075 | } |
| 9076 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9077 | enforceTelephonyFeatureWithException(callingPackage, |
| 9078 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9079 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9080 | final long identity = Binder.clearCallingIdentity(); |
| 9081 | try { |
| 9082 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9083 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9084 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9085 | } |
| 9086 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9087 | } finally { |
| 9088 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9089 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9090 | } |
| 9091 | |
| 9092 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9093 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9094 | * |
| 9095 | * @throws SecurityException if the caller does not have the required permission |
| 9096 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9097 | @VisibleForTesting |
| 9098 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9099 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9100 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9101 | } |
| 9102 | |
| 9103 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9104 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9105 | * permission. |
| 9106 | * |
| 9107 | * @throws SecurityException if the caller does not have the required permission |
| 9108 | */ |
| 9109 | private void enforceSendSmsPermission() { |
| 9110 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9111 | } |
| 9112 | |
| 9113 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9114 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9115 | * users permission. |
| 9116 | * |
| 9117 | * @throws SecurityException if the caller does not have the required permission |
| 9118 | */ |
| 9119 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9120 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9121 | } |
| 9122 | |
| 9123 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9124 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9125 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9126 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9127 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9128 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9129 | final long identity = Binder.clearCallingIdentity(); |
| 9130 | try { |
| 9131 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9132 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9133 | if (componentName == null) { |
| 9134 | throw new SecurityException( |
| 9135 | "Caller not current active visual voicemail package[null]"); |
| 9136 | } |
| 9137 | String vvmPackage = componentName.getPackageName(); |
| 9138 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9139 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9140 | } |
| 9141 | } finally { |
| 9142 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9143 | } |
| 9144 | } |
| 9145 | |
| 9146 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9147 | * Return the application ID for the app type. |
| 9148 | * |
| 9149 | * @param subId the subscription ID that this request applies to. |
| 9150 | * @param appType the uicc app type. |
| 9151 | * @return Application ID for specificied app type, or null if no uicc. |
| 9152 | */ |
| 9153 | @Override |
| 9154 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9155 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9156 | |
| 9157 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9158 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9159 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9160 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9161 | |
| 9162 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9163 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9164 | if (phone == null) { |
| 9165 | return null; |
| 9166 | } |
| 9167 | String aid = null; |
| 9168 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9169 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9170 | .getApplicationByType(appType).getAid(); |
| 9171 | } catch (Exception e) { |
| 9172 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9173 | } |
| 9174 | return aid; |
| 9175 | } finally { |
| 9176 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9177 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9178 | } |
| 9179 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9180 | /** |
| 9181 | * Return the Electronic Serial Number. |
| 9182 | * |
| 9183 | * @param subId the subscription ID that this request applies to. |
| 9184 | * @return ESN or null if error. |
| 9185 | */ |
| 9186 | @Override |
| 9187 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9188 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9189 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9190 | |
| 9191 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9192 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9193 | if (phone == null) { |
| 9194 | return null; |
| 9195 | } |
| 9196 | String esn = null; |
| 9197 | try { |
| 9198 | esn = phone.getEsn(); |
| 9199 | } catch (Exception e) { |
| 9200 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9201 | } |
| 9202 | return esn; |
| 9203 | } finally { |
| 9204 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9205 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9206 | } |
| 9207 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9208 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9209 | * Return the Preferred Roaming List Version. |
| 9210 | * |
| 9211 | * @param subId the subscription ID that this request applies to. |
| 9212 | * @return PRLVersion or null if error. |
| 9213 | */ |
| 9214 | @Override |
| 9215 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9216 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9217 | |
| 9218 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9219 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9220 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9221 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9222 | |
| 9223 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9224 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9225 | if (phone == null) { |
| 9226 | return null; |
| 9227 | } |
| 9228 | String cdmaPrlVersion = null; |
| 9229 | try { |
| 9230 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9231 | } catch (Exception e) { |
| 9232 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9233 | } |
| 9234 | return cdmaPrlVersion; |
| 9235 | } finally { |
| 9236 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9237 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9238 | } |
| 9239 | |
| 9240 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9241 | * Get snapshot of Telephony histograms |
| 9242 | * @return List of Telephony histograms |
| 9243 | * @hide |
| 9244 | */ |
| 9245 | @Override |
| 9246 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9248 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9249 | |
| 9250 | final long identity = Binder.clearCallingIdentity(); |
| 9251 | try { |
| 9252 | return RIL.getTelephonyRILTimingHistograms(); |
| 9253 | } finally { |
| 9254 | Binder.restoreCallingIdentity(identity); |
| 9255 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9256 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9257 | |
| 9258 | /** |
| 9259 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9260 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9261 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9262 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9263 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9264 | * @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] | 9265 | */ |
| 9266 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9267 | @TelephonyManager.SetCarrierRestrictionResult |
| 9268 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9269 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9270 | |
| 9271 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9272 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9273 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9274 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9275 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9276 | if (carrierRestrictionRules == null) { |
| 9277 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9278 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9279 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9280 | final long identity = Binder.clearCallingIdentity(); |
| 9281 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9282 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9283 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9284 | } finally { |
| 9285 | Binder.restoreCallingIdentity(identity); |
| 9286 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9287 | } |
| 9288 | |
| 9289 | /** |
| 9290 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9291 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9292 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9293 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9294 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9295 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9296 | */ |
| 9297 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9298 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9299 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9300 | |
| 9301 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9302 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9303 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9304 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9305 | |
| 9306 | final long identity = Binder.clearCallingIdentity(); |
| 9307 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9308 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9309 | if (response instanceof CarrierRestrictionRules) { |
| 9310 | return (CarrierRestrictionRules) response; |
| 9311 | } |
| 9312 | // Response is an Exception of some kind, |
| 9313 | // which is signalled to the user as a NULL retval |
| 9314 | return null; |
| 9315 | } catch (Exception e) { |
| 9316 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9317 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9318 | } finally { |
| 9319 | Binder.restoreCallingIdentity(identity); |
| 9320 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9321 | } |
| 9322 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9323 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9324 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9325 | * through the callback. |
| 9326 | * |
| 9327 | * @param callback The callback that will be used to send the result. |
| 9328 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9329 | * the caller is not allowlisted. |
| 9330 | */ |
| 9331 | @Override |
| 9332 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9333 | String functionName = "getCarrierRestrictionStatus"; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9334 | enforceTelephonyFeatureWithException(packageName, |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9335 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName); |
| 9336 | try { |
| 9337 | mApp.enforceCallingOrSelfPermission( |
| 9338 | android.Manifest.permission.READ_BASIC_PHONE_STATE, |
| 9339 | functionName); |
| 9340 | } catch (SecurityException e) { |
| 9341 | mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE, |
| 9342 | functionName); |
| 9343 | } |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9344 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9345 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9346 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9347 | throw new SecurityException("Not an authorized caller"); |
| 9348 | } |
| 9349 | final long identity = Binder.clearCallingIdentity(); |
| 9350 | try { |
| 9351 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9352 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9353 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9354 | } finally { |
| 9355 | Binder.restoreCallingIdentity(identity); |
| 9356 | } |
| 9357 | } |
| 9358 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9359 | @Override |
| 9360 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9361 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9362 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9363 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9364 | } |
| 9365 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9366 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9367 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9368 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9369 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9370 | } |
| 9371 | |
| 9372 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9373 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9374 | * @param subId the subscription ID that this action applies to. |
| 9375 | * @param enabled control enable or disable radio. |
| 9376 | * {@hide} |
| 9377 | */ |
| 9378 | @Override |
| 9379 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9380 | enforceModifyPermission(); |
| 9381 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9382 | |
| 9383 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9384 | if (phone == null) { |
| 9385 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9386 | return; |
| 9387 | } |
| 9388 | try { |
| 9389 | phone.carrierActionSetRadioEnabled(enabled); |
| 9390 | } catch (Exception e) { |
| 9391 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9392 | } finally { |
| 9393 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9394 | } |
| 9395 | } |
| 9396 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9397 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9398 | * Enable or disable Voice over NR (VoNR) |
| 9399 | * @param subId the subscription ID that this action applies to. |
| 9400 | * @param enabled enable or disable VoNR. |
| 9401 | * @return operation result. |
| 9402 | */ |
| 9403 | @Override |
| 9404 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9405 | enforceModifyPermission(); |
| 9406 | final Phone phone = getPhone(subId); |
| 9407 | |
| 9408 | final long identity = Binder.clearCallingIdentity(); |
| 9409 | if (phone == null) { |
| 9410 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9411 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9412 | } |
| 9413 | |
| 9414 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9415 | try { |
| 9416 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9417 | workSource); |
| 9418 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9419 | |
| 9420 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9421 | if (DBG) { |
| 9422 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9423 | } |
| 9424 | SubscriptionManager.setSubscriptionProperty( |
| 9425 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9426 | (enabled ? "1" : "0")); |
| 9427 | } |
| 9428 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9429 | return result; |
| 9430 | } finally { |
| 9431 | Binder.restoreCallingIdentity(identity); |
| 9432 | } |
| 9433 | } |
| 9434 | |
| 9435 | /** |
| 9436 | * Is voice over NR enabled |
| 9437 | * @return true if VoNR is enabled else false |
| 9438 | */ |
| 9439 | @Override |
| 9440 | public boolean isVoNrEnabled(int subId) { |
| 9441 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9442 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9443 | final long identity = Binder.clearCallingIdentity(); |
| 9444 | try { |
| 9445 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9446 | null, subId, workSource); |
| 9447 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9448 | return isEnabled; |
| 9449 | } finally { |
| 9450 | Binder.restoreCallingIdentity(identity); |
| 9451 | } |
| 9452 | } |
| 9453 | |
| 9454 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9455 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9456 | * network status based on which carrier apps could apply actions accordingly, |
| 9457 | * enable/disable default url handler for example. |
| 9458 | * |
| 9459 | * @param subId the subscription ID that this action applies to. |
| 9460 | * @param report control start/stop reporting the default network status. |
| 9461 | * {@hide} |
| 9462 | */ |
| 9463 | @Override |
| 9464 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9465 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9466 | |
| 9467 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9468 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9469 | "carrierActionReportDefaultNetworkStatus"); |
| 9470 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9471 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9472 | |
| 9473 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9474 | if (phone == null) { |
| 9475 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9476 | return; |
| 9477 | } |
| 9478 | try { |
| 9479 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9480 | } catch (Exception e) { |
| 9481 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9482 | } finally { |
| 9483 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9484 | } |
| 9485 | } |
| 9486 | |
| 9487 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9488 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9489 | * @param subId the subscription ID that this action applies to. |
| 9490 | * {@hide} |
| 9491 | */ |
| 9492 | @Override |
| 9493 | public void carrierActionResetAll(int subId) { |
| 9494 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9495 | |
| 9496 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9497 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9498 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9499 | final Phone phone = getPhone(subId); |
| 9500 | if (phone == null) { |
| 9501 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9502 | return; |
| 9503 | } |
| 9504 | try { |
| 9505 | phone.carrierActionResetAll(); |
| 9506 | } catch (Exception e) { |
| 9507 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9508 | } |
| 9509 | } |
| 9510 | |
| 9511 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9512 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9513 | * bug report is being generated. |
| 9514 | */ |
| 9515 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9516 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9517 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9518 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9519 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9520 | + Binder.getCallingPid() |
| 9521 | + ", uid=" + Binder.getCallingUid() |
| 9522 | + "without permission " |
| 9523 | + android.Manifest.permission.DUMP); |
| 9524 | return; |
| 9525 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9526 | try { |
| 9527 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9528 | } catch (Exception e) { |
| 9529 | writer.println("Failed to dump phone information: " + e); |
| 9530 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9531 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9532 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9533 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9534 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9535 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9536 | @NonNull String[] args) { |
| 9537 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9538 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9539 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9540 | } |
| 9541 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9542 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9543 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9544 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9545 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9546 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9547 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9548 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9549 | */ |
| 9550 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9551 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9552 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9553 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9554 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9555 | try { |
| 9556 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9557 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9558 | } catch (SecurityException se) { |
| 9559 | enforceModifyPermission(); |
| 9560 | } |
| 9561 | } else { |
| 9562 | enforceModifyPermission(); |
| 9563 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9564 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9565 | enforceTelephonyFeatureWithException(callingPackage, |
| 9566 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9567 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9568 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9569 | final long identity = Binder.clearCallingIdentity(); |
| 9570 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9571 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9572 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9573 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9574 | callingUid, callingPackage, null, null); |
| 9575 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9576 | Phone phone = getPhone(subId); |
| 9577 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9578 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9579 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9580 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9581 | phone.getDataSettingsManager().setDataEnabled( |
| 9582 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9583 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9584 | } |
| 9585 | } finally { |
| 9586 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9587 | } |
| 9588 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9589 | |
| 9590 | /** |
| 9591 | * Get Client request stats |
| 9592 | * @return List of Client Request Stats |
| 9593 | * @hide |
| 9594 | */ |
| 9595 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9596 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9597 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9598 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9599 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9600 | return null; |
| 9601 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9602 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9603 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9604 | final long identity = Binder.clearCallingIdentity(); |
| 9605 | try { |
| 9606 | if (phone != null) { |
| 9607 | return phone.getClientRequestStats(); |
| 9608 | } |
| 9609 | |
| 9610 | return null; |
| 9611 | } finally { |
| 9612 | Binder.restoreCallingIdentity(identity); |
| 9613 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9614 | } |
| 9615 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9616 | private WorkSource getWorkSource(int uid) { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 9617 | PackageManager pm; |
| 9618 | if (mFeatureFlags.hsumPackageManager()) { |
| 9619 | pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0) |
| 9620 | .getPackageManager(); |
| 9621 | } else { |
| 9622 | pm = mApp.getPackageManager(); |
| 9623 | } |
| 9624 | |
| 9625 | String packageName = pm.getNameForUid(uid); |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 9626 | if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) { |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9627 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9628 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9629 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9630 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9631 | // commands that plumb through the RIL as root, like so: |
| 9632 | // $ adb root |
| 9633 | // $ adb shell cmd phone ... |
| 9634 | packageName = "root"; |
| 9635 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9636 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9637 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9638 | |
| 9639 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9640 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9641 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9642 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9643 | * @param state State of SIM (power down, power up, pass through) |
| 9644 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9645 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9646 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9647 | * |
| 9648 | **/ |
| 9649 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9650 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9651 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9652 | |
| 9653 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9654 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9655 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9656 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9657 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9658 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9659 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9660 | final long identity = Binder.clearCallingIdentity(); |
| 9661 | try { |
| 9662 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9663 | phone.setSimPowerState(state, null, workSource); |
| 9664 | } |
| 9665 | } finally { |
| 9666 | Binder.restoreCallingIdentity(identity); |
| 9667 | } |
| 9668 | } |
| 9669 | |
| 9670 | /** |
| 9671 | * Set SIM card power state. |
| 9672 | * |
| 9673 | * @param slotIndex SIM slot id. |
| 9674 | * @param state State of SIM (power down, power up, pass through) |
| 9675 | * @param callback callback to trigger after success or failure |
| 9676 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9677 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9678 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9679 | * |
| 9680 | **/ |
| 9681 | @Override |
| 9682 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9683 | IIntegerConsumer callback) { |
| 9684 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9685 | |
| 9686 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9687 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9688 | "setSimPowerStateForSlotWithCallback"); |
| 9689 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9690 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9691 | |
| 9692 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9693 | |
| 9694 | final long identity = Binder.clearCallingIdentity(); |
| 9695 | try { |
| 9696 | if (phone != null) { |
| 9697 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9698 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9699 | } |
| 9700 | } finally { |
| 9701 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9702 | } |
| 9703 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9704 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9705 | private boolean isUssdApiAllowed(int subId) { |
| 9706 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9707 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9708 | if (configManager == null) { |
| 9709 | return false; |
| 9710 | } |
| 9711 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9712 | if (pb == null) { |
| 9713 | return false; |
| 9714 | } |
| 9715 | return pb.getBoolean( |
| 9716 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9717 | } |
| 9718 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9719 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9720 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9721 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9722 | * @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] | 9723 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9724 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9725 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9726 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9727 | |
| 9728 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9729 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9730 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9731 | final long identity = Binder.clearCallingIdentity(); |
| 9732 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9733 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9734 | } finally { |
| 9735 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9736 | } |
| 9737 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9738 | |
| 9739 | /** |
| 9740 | * Get the current signal strength information for the given subscription. |
| 9741 | * Because this information is not updated when the device is in a low power state |
| 9742 | * it should not be relied-upon to be current. |
| 9743 | * @param subId Subscription index |
| 9744 | * @return the most recent cached signal strength info from the modem |
| 9745 | */ |
| 9746 | @Override |
| 9747 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9748 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9749 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9751 | final long identity = Binder.clearCallingIdentity(); |
| 9752 | try { |
| 9753 | Phone p = getPhone(subId); |
| 9754 | if (p == null) { |
| 9755 | return null; |
| 9756 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9757 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9758 | return p.getSignalStrength(); |
| 9759 | } finally { |
| 9760 | Binder.restoreCallingIdentity(identity); |
| 9761 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9762 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9763 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9764 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9765 | * Get the current modem radio state for the given slot. |
| 9766 | * @param slotIndex slot index. |
| 9767 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9768 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9769 | * @return the current radio power state from the modem |
| 9770 | */ |
| 9771 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9772 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9773 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9774 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9775 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9776 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9777 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9778 | } |
| 9779 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9780 | enforceTelephonyFeatureWithException(callingPackage, |
| 9781 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9782 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9783 | final long identity = Binder.clearCallingIdentity(); |
| 9784 | try { |
| 9785 | return phone.getRadioPowerState(); |
| 9786 | } finally { |
| 9787 | Binder.restoreCallingIdentity(identity); |
| 9788 | } |
| 9789 | } |
| 9790 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9791 | } |
| 9792 | |
| 9793 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9794 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9795 | * |
| 9796 | * <p>Requires one of the following permissions: |
| 9797 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9798 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9799 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9800 | * privileges. |
| 9801 | * |
| 9802 | * @param subId subscription id |
| 9803 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9804 | * {@code false}. |
| 9805 | */ |
| 9806 | @Override |
| 9807 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9808 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9809 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9810 | try { |
| 9811 | mApp.enforceCallingOrSelfPermission( |
| 9812 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9813 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9814 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9815 | mApp.enforceCallingOrSelfPermission( |
| 9816 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9817 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9818 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9819 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9820 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9821 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9822 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9823 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9824 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9825 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9826 | boolean isEnabled = false; |
| 9827 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9828 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9829 | Phone phone = getPhone(subId); |
| 9830 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9831 | } finally { |
| 9832 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9833 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9834 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9835 | } |
| 9836 | |
| 9837 | |
| 9838 | /** |
| 9839 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9840 | * |
| 9841 | * <p> Requires permission: |
| 9842 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9843 | * privileges. |
| 9844 | * |
| 9845 | * @param subId subscription id |
| 9846 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9847 | */ |
| 9848 | @Override |
| 9849 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9850 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9851 | mApp, subId, "setDataRoamingEnabled"); |
| 9852 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9853 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9854 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9855 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9856 | final long identity = Binder.clearCallingIdentity(); |
| 9857 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9858 | Phone phone = getPhone(subId); |
| 9859 | if (phone != null) { |
| 9860 | phone.setDataRoamingEnabled(isEnabled); |
| 9861 | } |
| 9862 | } finally { |
| 9863 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9864 | } |
| 9865 | } |
| 9866 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9867 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9868 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9869 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9870 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9871 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9872 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9873 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9874 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9875 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9876 | boolean isAllowed = true; |
| 9877 | final long identity = Binder.clearCallingIdentity(); |
| 9878 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9879 | Phone phone = getPhone(subId); |
| 9880 | if (phone != null) { |
| 9881 | isAllowed = phone.isCspPlmnEnabled(); |
| 9882 | } |
| 9883 | } finally { |
| 9884 | Binder.restoreCallingIdentity(identity); |
| 9885 | } |
| 9886 | return isAllowed; |
| 9887 | } |
| 9888 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9889 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9890 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9891 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9892 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9893 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9894 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9895 | if (phone == null) { |
| 9896 | return false; |
| 9897 | } |
| 9898 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9899 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9900 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9901 | } |
| 9902 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9903 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9904 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9905 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9906 | mApp.getSystemService(AppOpsManager.class) |
| 9907 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9908 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9909 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9910 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9911 | try { |
| 9912 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9913 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9914 | } catch (SecurityException e) { |
| 9915 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9916 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9917 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9918 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9919 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9920 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9921 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9922 | |
| 9923 | enforceTelephonyFeatureWithException(callingPackage, |
| 9924 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9925 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9926 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9927 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9928 | Binder.getCallingUid())) { |
| 9929 | isIccIdAccessRestricted = true; |
| 9930 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9931 | final long identity = Binder.clearCallingIdentity(); |
| 9932 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9933 | UiccController uiccController = UiccController.getInstance(); |
| 9934 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9935 | if (hasReadPermission) { |
| 9936 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9937 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9938 | |
| 9939 | // Remove private info if the caller doesn't have access |
| 9940 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9941 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9942 | //setting the value after compatibility check |
| 9943 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9944 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9945 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9946 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9947 | if (card == null) { |
| 9948 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9949 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9950 | continue; |
| 9951 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9952 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9953 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9954 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9955 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9956 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9957 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9958 | for (UiccPortInfo portInfo : portInfos) { |
| 9959 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9960 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9961 | if (port == null) { |
| 9962 | // assume no access if port is null |
| 9963 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9964 | continue; |
| 9965 | } |
| 9966 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9967 | uiccPortInfos.add(portInfo); |
| 9968 | } else { |
| 9969 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9970 | } |
| 9971 | } |
| 9972 | filteredInfos.add(new UiccCardInfo( |
| 9973 | cardInfo.isEuicc(), |
| 9974 | cardInfo.getCardId(), |
| 9975 | null, |
| 9976 | cardInfo.getPhysicalSlotIndex(), |
| 9977 | cardInfo.isRemovable(), |
| 9978 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9979 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9980 | } |
| 9981 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9982 | } finally { |
| 9983 | Binder.restoreCallingIdentity(identity); |
| 9984 | } |
| 9985 | } |
| 9986 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9987 | /** |
| 9988 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9989 | * generally private and require carrier privileges to view. |
| 9990 | * |
| 9991 | * @hide |
| 9992 | */ |
| 9993 | @NonNull |
| 9994 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9995 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9996 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9997 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9998 | } |
| 9999 | return new UiccCardInfo( |
| 10000 | cardInfo.isEuicc(), |
| 10001 | cardInfo.getCardId(), |
| 10002 | null, |
| 10003 | cardInfo.getPhysicalSlotIndex(), |
| 10004 | cardInfo.isRemovable(), |
| 10005 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10006 | portinfo |
| 10007 | ); |
| 10008 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10009 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10010 | /** |
| 10011 | * @hide |
| 10012 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 10013 | * These values are generally private and require carrier privileges to view. |
| 10014 | */ |
| 10015 | @NonNull |
| 10016 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 10017 | return new UiccPortInfo( |
| 10018 | UiccPortInfo.ICCID_REDACTED, |
| 10019 | portInfo.getPortIndex(), |
| 10020 | portInfo.getLogicalSlotIndex(), |
| 10021 | portInfo.isActive() |
| 10022 | ); |
| 10023 | } |
| 10024 | @Override |
| 10025 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10026 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10027 | mApp.getSystemService(AppOpsManager.class) |
| 10028 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10029 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10030 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10031 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10032 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10033 | // we are reading iccId which is PII data. |
| 10034 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10035 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10036 | enforceTelephonyFeatureWithException(callingPackage, |
| 10037 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10038 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10039 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10040 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10041 | Binder.getCallingUid())) { |
| 10042 | isLogicalSlotAccessRestricted = true; |
| 10043 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10044 | final long identity = Binder.clearCallingIdentity(); |
| 10045 | try { |
| 10046 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10047 | if (slots == null || slots.length == 0) { |
| 10048 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10049 | return null; |
| 10050 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10051 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10052 | for (int i = 0; i < slots.length; i++) { |
| 10053 | UiccSlot slot = slots[i]; |
| 10054 | if (slot == null) { |
| 10055 | continue; |
| 10056 | } |
| 10057 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10058 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10059 | UiccCard card = slot.getUiccCard(); |
| 10060 | if (card != null) { |
| 10061 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10062 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10063 | cardId = slot.getEid(); |
| 10064 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10065 | // If cardId is null, use iccId of default port as cardId. |
| 10066 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10067 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10068 | } |
| 10069 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10070 | if (cardId != null) { |
| 10071 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10072 | // if cardId is an EID, it's all digits so this is fine |
| 10073 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10074 | } |
| 10075 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10076 | int cardState = 0; |
| 10077 | switch (slot.getCardState()) { |
| 10078 | case CARDSTATE_ABSENT: |
| 10079 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10080 | break; |
| 10081 | case CARDSTATE_PRESENT: |
| 10082 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10083 | break; |
| 10084 | case CARDSTATE_ERROR: |
| 10085 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10086 | break; |
| 10087 | case CARDSTATE_RESTRICTED: |
| 10088 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10089 | break; |
| 10090 | default: |
| 10091 | break; |
| 10092 | |
| 10093 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10094 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10095 | int[] portIndexes = slot.getPortList(); |
| 10096 | for (int portIdx : portIndexes) { |
| 10097 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10098 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10099 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10100 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10101 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10102 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10103 | slot.isEuicc(), |
| 10104 | cardId, |
| 10105 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10106 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10107 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10108 | //setting the value after compatibility check |
| 10109 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10110 | } |
| 10111 | return infos; |
| 10112 | } finally { |
| 10113 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10114 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10115 | } |
| 10116 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10117 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10118 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10119 | boolean hasReadPermission) { |
| 10120 | String iccId = slot.getIccId(portIndex); |
| 10121 | if (hasReadPermission) { // if has read permission |
| 10122 | return iccId; |
| 10123 | } else { |
| 10124 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10125 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10126 | // if no read permission, checking carrier privilege access |
| 10127 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10128 | return iccId; |
| 10129 | } |
| 10130 | } |
| 10131 | } |
| 10132 | // No read permission or carrier privilege access. |
| 10133 | return UiccPortInfo.ICCID_REDACTED; |
| 10134 | } |
| 10135 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10136 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10137 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10138 | public boolean switchSlots(int[] physicalSlots) { |
| 10139 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10140 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10141 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10142 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10143 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10144 | final long identity = Binder.clearCallingIdentity(); |
| 10145 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10146 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10147 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10148 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10149 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10150 | physicalSlots[i], i)); |
| 10151 | } |
| 10152 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10153 | } finally { |
| 10154 | Binder.restoreCallingIdentity(identity); |
| 10155 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10156 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10157 | |
| 10158 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10159 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10160 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10161 | enforceModifyPermission(); |
| 10162 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10163 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10164 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10165 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10166 | final long identity = Binder.clearCallingIdentity(); |
| 10167 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10168 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10169 | } finally { |
| 10170 | Binder.restoreCallingIdentity(identity); |
| 10171 | } |
| 10172 | } |
| 10173 | |
| 10174 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10175 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10176 | enforceTelephonyFeatureWithException(callingPackage, |
| 10177 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10178 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10179 | final long identity = Binder.clearCallingIdentity(); |
| 10180 | try { |
| 10181 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10182 | } finally { |
| 10183 | Binder.restoreCallingIdentity(identity); |
| 10184 | } |
| 10185 | } |
| 10186 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10187 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10188 | * A test API to reload the UICC profile. |
| 10189 | * |
| 10190 | * <p>Requires that the calling app has permission |
| 10191 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10192 | * @hide |
| 10193 | */ |
| 10194 | @Override |
| 10195 | public void refreshUiccProfile(int subId) { |
| 10196 | enforceModifyPermission(); |
| 10197 | |
| 10198 | final long identity = Binder.clearCallingIdentity(); |
| 10199 | try { |
| 10200 | Phone phone = getPhone(subId); |
| 10201 | if (phone == null) { |
| 10202 | return; |
| 10203 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10204 | UiccPort uiccPort = phone.getUiccPort(); |
| 10205 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10206 | return; |
| 10207 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10208 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10209 | if (uiccProfile == null) { |
| 10210 | return; |
| 10211 | } |
| 10212 | uiccProfile.refresh(); |
| 10213 | } finally { |
| 10214 | Binder.restoreCallingIdentity(identity); |
| 10215 | } |
| 10216 | } |
| 10217 | |
| 10218 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10219 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10220 | */ |
| 10221 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10222 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10223 | } |
| 10224 | |
| 10225 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10226 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10227 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10228 | */ |
| 10229 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10230 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10231 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10232 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10233 | return list.get(phoneId); |
| 10234 | } |
| 10235 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10236 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10237 | |
| 10238 | @Override |
| 10239 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10240 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10241 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10242 | |
| 10243 | final long identity = Binder.clearCallingIdentity(); |
| 10244 | try { |
| 10245 | final Phone phone = getPhone(subId); |
| 10246 | if (phone == null) { |
| 10247 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10248 | return; |
| 10249 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10250 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10251 | if (cpt != null) { |
| 10252 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10253 | } |
| 10254 | // 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] | 10255 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10256 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10257 | if (carrierPrivilegeRules == null) { |
| 10258 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10259 | } else { |
| 10260 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10261 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10262 | } finally { |
| 10263 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10264 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10265 | } |
| 10266 | |
| 10267 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10268 | public void setCarrierServicePackageOverride( |
| 10269 | int subId, String carrierServicePackage, String callingPackage) { |
| 10270 | TelephonyPermissions.enforceShellOnly( |
| 10271 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10272 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10273 | final long identity = Binder.clearCallingIdentity(); |
| 10274 | try { |
| 10275 | final Phone phone = getPhone(subId); |
| 10276 | if (phone == null || phone.getSubId() != subId) { |
| 10277 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10278 | throw new IllegalArgumentException("No phone for subid"); |
| 10279 | } |
| 10280 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10281 | if (cpt == null) { |
| 10282 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10283 | throw new IllegalStateException("No CPT for phone"); |
| 10284 | } |
| 10285 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10286 | } finally { |
| 10287 | Binder.restoreCallingIdentity(identity); |
| 10288 | } |
| 10289 | } |
| 10290 | |
| 10291 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10292 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10293 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10294 | |
| 10295 | final long identity = Binder.clearCallingIdentity(); |
| 10296 | try { |
| 10297 | final Phone phone = getPhone(subId); |
| 10298 | if (phone == null) { |
| 10299 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10300 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10301 | } |
| 10302 | return phone.getCarrierIdListVersion(); |
| 10303 | } finally { |
| 10304 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10305 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10306 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10307 | |
| 10308 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10309 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10310 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10311 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10312 | mApp, subId, callingPackage, callingFeatureId, |
| 10313 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10314 | return -1; |
| 10315 | } |
| 10316 | |
| 10317 | final long identity = Binder.clearCallingIdentity(); |
| 10318 | try { |
| 10319 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10320 | } finally { |
| 10321 | Binder.restoreCallingIdentity(identity); |
| 10322 | } |
| 10323 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10324 | |
| 10325 | @Override |
| 10326 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10327 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10328 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10329 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10330 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10331 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10332 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10333 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10334 | final long identity = Binder.clearCallingIdentity(); |
| 10335 | try { |
| 10336 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10337 | } finally { |
| 10338 | Binder.restoreCallingIdentity(identity); |
| 10339 | } |
| 10340 | } |
| 10341 | |
| 10342 | @Override |
| 10343 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10345 | mApp, subId, "setCdmaRoamingMode"); |
| 10346 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10347 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10348 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10349 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10350 | final long identity = Binder.clearCallingIdentity(); |
| 10351 | try { |
| 10352 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10353 | } finally { |
| 10354 | Binder.restoreCallingIdentity(identity); |
| 10355 | } |
| 10356 | } |
| 10357 | |
| 10358 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10359 | public int getCdmaSubscriptionMode(int subId) { |
| 10360 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10361 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10362 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10363 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10364 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10365 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10366 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10367 | final long identity = Binder.clearCallingIdentity(); |
| 10368 | try { |
| 10369 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10370 | } finally { |
| 10371 | Binder.restoreCallingIdentity(identity); |
| 10372 | } |
| 10373 | } |
| 10374 | |
| 10375 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10376 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10377 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10378 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10379 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10380 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10381 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10382 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10383 | final long identity = Binder.clearCallingIdentity(); |
| 10384 | try { |
| 10385 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10386 | } finally { |
| 10387 | Binder.restoreCallingIdentity(identity); |
| 10388 | } |
| 10389 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10390 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10391 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10392 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10393 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10395 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10396 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10397 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10398 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10399 | |
| 10400 | enforceTelephonyFeatureWithException(callingPackage, |
| 10401 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10402 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10403 | final long identity = Binder.clearCallingIdentity(); |
| 10404 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10405 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10406 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10407 | if (phone.getEmergencyNumberTracker() != null |
| 10408 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10409 | emergencyNumberListInternal.put( |
| 10410 | phone.getSubId(), |
| 10411 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10412 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10413 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10414 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10415 | } finally { |
| 10416 | Binder.restoreCallingIdentity(identity); |
| 10417 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10418 | } |
| 10419 | |
| 10420 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10421 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10422 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10423 | if (!exactMatch) { |
| 10424 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10425 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10426 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10427 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10428 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 10429 | if (!mApp.getResources().getBoolean( |
| 10430 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 10431 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10432 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10433 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10434 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10435 | final long identity = Binder.clearCallingIdentity(); |
| 10436 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10437 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10438 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10439 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10440 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10441 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10442 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10443 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10444 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10445 | } |
| 10446 | return false; |
| 10447 | } finally { |
| 10448 | Binder.restoreCallingIdentity(identity); |
| 10449 | } |
| 10450 | } |
| 10451 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10452 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10453 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10454 | */ |
| 10455 | @Override |
| 10456 | public void startEmergencyCallbackMode() { |
| 10457 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10458 | "startEmergencyCallbackMode"); |
| 10459 | enforceModifyPermission(); |
| 10460 | final long identity = Binder.clearCallingIdentity(); |
| 10461 | try { |
| 10462 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10463 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10464 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10465 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10466 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10467 | gsmCdmaPhone.obtainMessage( |
| 10468 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10469 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10470 | } |
| 10471 | } |
| 10472 | } finally { |
| 10473 | Binder.restoreCallingIdentity(identity); |
| 10474 | } |
| 10475 | } |
| 10476 | |
| 10477 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10478 | * Update emergency number list for test mode. |
| 10479 | */ |
| 10480 | @Override |
| 10481 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10482 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10483 | "updateEmergencyNumberListTestMode"); |
| 10484 | |
| 10485 | final long identity = Binder.clearCallingIdentity(); |
| 10486 | try { |
| 10487 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10488 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10489 | if (tracker != null) { |
| 10490 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10491 | } |
| 10492 | } |
| 10493 | } finally { |
| 10494 | Binder.restoreCallingIdentity(identity); |
| 10495 | } |
| 10496 | } |
| 10497 | |
| 10498 | /** |
| 10499 | * Get the full emergency number list for test mode. |
| 10500 | */ |
| 10501 | @Override |
| 10502 | public List<String> getEmergencyNumberListTestMode() { |
| 10503 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10504 | "getEmergencyNumberListTestMode"); |
| 10505 | |
| 10506 | final long identity = Binder.clearCallingIdentity(); |
| 10507 | try { |
| 10508 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10509 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10510 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10511 | if (tracker != null) { |
| 10512 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10513 | emergencyNumbers.add(num.getNumber()); |
| 10514 | } |
| 10515 | } |
| 10516 | } |
| 10517 | return new ArrayList<>(emergencyNumbers); |
| 10518 | } finally { |
| 10519 | Binder.restoreCallingIdentity(identity); |
| 10520 | } |
| 10521 | } |
| 10522 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10523 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10524 | public int getEmergencyNumberDbVersion(int subId) { |
| 10525 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10526 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10527 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10528 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10529 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10530 | final long identity = Binder.clearCallingIdentity(); |
| 10531 | try { |
| 10532 | final Phone phone = getPhone(subId); |
| 10533 | if (phone == null) { |
| 10534 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10535 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10536 | } |
| 10537 | return phone.getEmergencyNumberDbVersion(); |
| 10538 | } finally { |
| 10539 | Binder.restoreCallingIdentity(identity); |
| 10540 | } |
| 10541 | } |
| 10542 | |
| 10543 | @Override |
| 10544 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10545 | enforceModifyPermission(); |
| 10546 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10547 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10548 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10549 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10550 | final long identity = Binder.clearCallingIdentity(); |
| 10551 | try { |
| 10552 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10553 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10554 | if (tracker != null) { |
| 10555 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10556 | } |
| 10557 | } |
| 10558 | } finally { |
| 10559 | Binder.restoreCallingIdentity(identity); |
| 10560 | } |
| 10561 | } |
| 10562 | |
| 10563 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10564 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10565 | enforceActiveEmergencySessionPermission(); |
| 10566 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10567 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10568 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10569 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10570 | final long identity = Binder.clearCallingIdentity(); |
| 10571 | try { |
| 10572 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10573 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10574 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10575 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10576 | } |
| 10577 | } |
| 10578 | } finally { |
| 10579 | Binder.restoreCallingIdentity(identity); |
| 10580 | } |
| 10581 | } |
| 10582 | |
| 10583 | @Override |
| 10584 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10585 | enforceActiveEmergencySessionPermission(); |
| 10586 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10587 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10588 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10589 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10590 | final long identity = Binder.clearCallingIdentity(); |
| 10591 | try { |
| 10592 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10593 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10594 | if (tracker != null) { |
| 10595 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10596 | } |
| 10597 | } |
| 10598 | } finally { |
| 10599 | Binder.restoreCallingIdentity(identity); |
| 10600 | } |
| 10601 | } |
| 10602 | |
| 10603 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10604 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10605 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10606 | Phone phone = getPhone(subId); |
| 10607 | if (phone == null) { |
| 10608 | return null; |
| 10609 | } |
| 10610 | final long identity = Binder.clearCallingIdentity(); |
| 10611 | try { |
| 10612 | UiccProfile profile = UiccController.getInstance() |
| 10613 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10614 | if (profile != null) { |
| 10615 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10616 | } |
| 10617 | } finally { |
| 10618 | Binder.restoreCallingIdentity(identity); |
| 10619 | } |
| 10620 | return null; |
| 10621 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10622 | |
| 10623 | /** |
| 10624 | * Enable or disable a modem stack. |
| 10625 | */ |
| 10626 | @Override |
| 10627 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10628 | enforceModifyPermission(); |
| 10629 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10630 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10631 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10632 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10633 | final long identity = Binder.clearCallingIdentity(); |
| 10634 | try { |
| 10635 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10636 | if (phone == null) { |
| 10637 | return false; |
| 10638 | } else { |
| 10639 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10640 | } |
| 10641 | } finally { |
| 10642 | Binder.restoreCallingIdentity(identity); |
| 10643 | } |
| 10644 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10645 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10646 | /** |
| 10647 | * Whether a modem stack is enabled or not. |
| 10648 | */ |
| 10649 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10650 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10651 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10652 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10653 | if (phone == null) return false; |
| 10654 | |
| 10655 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10656 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10657 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10658 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10659 | } |
| 10660 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10661 | enforceTelephonyFeatureWithException(callingPackage, |
| 10662 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10663 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10664 | final long identity = Binder.clearCallingIdentity(); |
| 10665 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10666 | try { |
| 10667 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10668 | } catch (NoSuchElementException ex) { |
| 10669 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10670 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10671 | } finally { |
| 10672 | Binder.restoreCallingIdentity(identity); |
| 10673 | } |
| 10674 | } |
| 10675 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10676 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10677 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10678 | enforceModifyPermission(); |
| 10679 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10680 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10681 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10682 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10683 | final long identity = Binder.clearCallingIdentity(); |
| 10684 | try { |
| 10685 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10686 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10687 | .commit(); |
| 10688 | } finally { |
| 10689 | Binder.restoreCallingIdentity(identity); |
| 10690 | } |
| 10691 | } |
| 10692 | |
| 10693 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10694 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10695 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10696 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10697 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10698 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10699 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10700 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10701 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10702 | enforceTelephonyFeatureWithException(callingPackage, |
| 10703 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10704 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10705 | final long identity = Binder.clearCallingIdentity(); |
| 10706 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10707 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10708 | } finally { |
| 10709 | Binder.restoreCallingIdentity(identity); |
| 10710 | } |
| 10711 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10712 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10713 | @TelephonyManager.IsMultiSimSupportedResult |
| 10714 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10715 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10716 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10717 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10718 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10719 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10720 | } |
| 10721 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10722 | // supported by the modem, indicate that it is restricted. |
| 10723 | PhoneCapability staticCapability = |
| 10724 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10725 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10726 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10727 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10728 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10729 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10730 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10731 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10732 | } |
| 10733 | // Check if support of multiple SIMs is restricted by carrier |
| 10734 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10735 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10736 | } |
| 10737 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10738 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10739 | } |
| 10740 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10741 | /** |
| 10742 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10743 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10744 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10745 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10746 | * @param numOfSims number of active sims we want to switch to |
| 10747 | */ |
| 10748 | @Override |
| 10749 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10750 | if (numOfSims == 1) { |
| 10751 | enforceModifyPermission(); |
| 10752 | } else { |
| 10753 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10754 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10755 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10756 | |
| 10757 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10758 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10759 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10760 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10761 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10762 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10763 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10764 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10765 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10766 | return; |
| 10767 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10768 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10769 | } finally { |
| 10770 | Binder.restoreCallingIdentity(identity); |
| 10771 | } |
| 10772 | } |
| 10773 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10774 | @Override |
| 10775 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10776 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10777 | |
| 10778 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10779 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10780 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10781 | Phone phone = getPhone(subId); |
| 10782 | if (phone == null) { |
| 10783 | return false; |
| 10784 | } |
| 10785 | final long identity = Binder.clearCallingIdentity(); |
| 10786 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10787 | UiccPort uiccPort = phone.getUiccPort(); |
| 10788 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10789 | return false; |
| 10790 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10791 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10792 | if (uiccProfile == null) { |
| 10793 | return false; |
| 10794 | } |
| 10795 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10796 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10797 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10798 | } |
| 10799 | return false; |
| 10800 | } finally { |
| 10801 | Binder.restoreCallingIdentity(identity); |
| 10802 | } |
| 10803 | } |
| 10804 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10805 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10806 | * Get whether making changes to modem configurations will trigger reboot. |
| 10807 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10808 | */ |
| 10809 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10810 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10811 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10812 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10813 | mApp, subId, callingPackage, callingFeatureId, |
| 10814 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10815 | return false; |
| 10816 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10817 | |
| 10818 | enforceTelephonyFeatureWithException(callingPackage, |
| 10819 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10820 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10821 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10822 | final long identity = Binder.clearCallingIdentity(); |
| 10823 | try { |
| 10824 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10825 | } finally { |
| 10826 | Binder.restoreCallingIdentity(identity); |
| 10827 | } |
| 10828 | } |
| 10829 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10830 | private void updateModemStateMetrics() { |
| 10831 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10832 | // TODO: check the state for each modem if the api is ready. |
| 10833 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10834 | } |
| 10835 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10836 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10837 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10838 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10839 | // Verify that the callingPackage belongs to the calling UID |
| 10840 | mApp.getSystemService(AppOpsManager.class) |
| 10841 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10842 | |
| 10843 | enforceTelephonyFeatureWithException(callingPackage, |
| 10844 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10845 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10846 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10847 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10848 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10849 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10850 | if (slotInfos != null) { |
| 10851 | for (int i = 0; i < slotInfos.length; i++) { |
| 10852 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10853 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10854 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10855 | portInfo.getLogicalSlotIndex())); |
| 10856 | } |
| 10857 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10858 | } |
| 10859 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10860 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10861 | } finally { |
| 10862 | Binder.restoreCallingIdentity(identity); |
| 10863 | } |
| 10864 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10865 | |
| 10866 | /** |
| 10867 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10868 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10869 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10870 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10871 | @Override |
| 10872 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10873 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10874 | } |
| 10875 | |
| 10876 | /** |
| 10877 | * Get the HAL Version of a specific service |
| 10878 | */ |
| 10879 | @Override |
| 10880 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10881 | Phone phone = getDefaultPhone(); |
| 10882 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10883 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10884 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10885 | return hv.major * 100 + hv.minor; |
| 10886 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10887 | |
| 10888 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10889 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10890 | * |
| 10891 | * @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] | 10892 | */ |
| 10893 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10894 | public @Nullable String getCurrentPackageName() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10895 | if (mFeatureFlags.hsumPackageManager()) { |
| 10896 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 10897 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10898 | if (pm == null) return null; |
| 10899 | String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid()); |
| 10900 | return (callingUids == null) ? null : callingUids[0]; |
| 10901 | } |
| 10902 | if (mPackageManager == null) return null; |
| 10903 | String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 10904 | return (callingUids == null) ? null : callingUids[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10905 | } |
| 10906 | |
| 10907 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10908 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10909 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10910 | * actually always the caller. |
| 10911 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10912 | */ |
| 10913 | private String getCurrentPackageNameOrPhone() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10914 | PackageManager pm; |
| 10915 | if (mFeatureFlags.hsumPackageManager()) { |
| 10916 | pm = mApp.getBaseContext().createContextAsUser( |
| 10917 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10918 | } else { |
| 10919 | pm = mApp.getPackageManager(); |
| 10920 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10921 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10922 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10923 | return getCurrentPackageName(); |
| 10924 | } |
| 10925 | |
| 10926 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10927 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10928 | * corresponding network requests on a subId. |
| 10929 | * |
| 10930 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10931 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10932 | * 2) APN is un-metered for this subscription, or |
| 10933 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10934 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10935 | * |
| 10936 | * @return whether data is allowed for a apn type. |
| 10937 | * |
| 10938 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10939 | */ |
| 10940 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10941 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10942 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10943 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10944 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10945 | enforceTelephonyFeatureWithException(callingPackage, |
| 10946 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10947 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10948 | // Now that all security checks passes, perform the operation as ourselves. |
| 10949 | final long identity = Binder.clearCallingIdentity(); |
| 10950 | try { |
| 10951 | Phone phone = getPhone(subId); |
| 10952 | if (phone == null) return false; |
| 10953 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10954 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10955 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10956 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10957 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10958 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10959 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10960 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10961 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10962 | } finally { |
| 10963 | Binder.restoreCallingIdentity(identity); |
| 10964 | } |
| 10965 | } |
| 10966 | |
| 10967 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10968 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10969 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10970 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10971 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10972 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10973 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10974 | // Now that all security checks passes, perform the operation as ourselves. |
| 10975 | final long identity = Binder.clearCallingIdentity(); |
| 10976 | try { |
| 10977 | Phone phone = getPhone(subId); |
| 10978 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10979 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10980 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10981 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10982 | } finally { |
| 10983 | Binder.restoreCallingIdentity(identity); |
| 10984 | } |
| 10985 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10986 | |
| 10987 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10988 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10989 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10990 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10991 | |
| 10992 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10993 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10994 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10995 | long token = Binder.clearCallingIdentity(); |
| 10996 | try { |
| 10997 | Phone phone = getPhone(subscriptionId); |
| 10998 | if (phone == null) { |
| 10999 | try { |
| 11000 | if (resultCallback != null) { |
| 11001 | resultCallback.accept(false); |
| 11002 | } |
| 11003 | } catch (RemoteException e) { |
| 11004 | // ignore |
| 11005 | } |
| 11006 | return; |
| 11007 | } |
| 11008 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 11009 | Pair.create(specifiers, (x) -> { |
| 11010 | try { |
| 11011 | if (resultCallback != null) { |
| 11012 | resultCallback.accept(x); |
| 11013 | } |
| 11014 | } catch (RemoteException e) { |
| 11015 | // ignore |
| 11016 | } |
| 11017 | }); |
| 11018 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 11019 | } finally { |
| 11020 | Binder.restoreCallingIdentity(token); |
| 11021 | } |
| 11022 | } |
| 11023 | |
| 11024 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11025 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 11026 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 11027 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11028 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11029 | |
| 11030 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11031 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 11032 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11033 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11034 | final long identity = Binder.clearCallingIdentity(); |
| 11035 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 11036 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 11037 | if (result instanceof IllegalStateException) { |
| 11038 | throw (IllegalStateException) result; |
| 11039 | } |
| 11040 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11041 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11042 | return specifiers; |
| 11043 | } finally { |
| 11044 | Binder.restoreCallingIdentity(identity); |
| 11045 | } |
| 11046 | } |
| 11047 | |
| 11048 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11049 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11050 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11051 | |
| 11052 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11053 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11054 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11055 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11056 | } |
| 11057 | |
| 11058 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11059 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11060 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11061 | if (callingPackage == null) { |
| 11062 | callingPackage = getCurrentPackageName(); |
| 11063 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11064 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11065 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11066 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11067 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11068 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11069 | } |
| 11070 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11071 | Intent intent = new Intent(); |
| 11072 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11073 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11074 | // Bring up choose default SMS subscription dialog right now |
| 11075 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11076 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11077 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11078 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11079 | |
| 11080 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11081 | public void showSwitchToManagedProfileDialog() { |
| 11082 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11083 | try { |
| 11084 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11085 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11086 | // for work telephony. |
| 11087 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11088 | intent.setData(Uri.parse("smsto:")); |
| 11089 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11090 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11091 | } catch (ActivityNotFoundException e) { |
| 11092 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11093 | Intent intent = new Intent(); |
| 11094 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11095 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11096 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11097 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11098 | } |
| 11099 | |
| 11100 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11101 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11102 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11103 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11104 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11105 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11106 | final long identity = Binder.clearCallingIdentity(); |
| 11107 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11108 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11109 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11110 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11111 | return carrierUAProfUrl; |
| 11112 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11113 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11114 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11115 | } finally { |
| 11116 | Binder.restoreCallingIdentity(identity); |
| 11117 | } |
| 11118 | } |
| 11119 | |
| 11120 | @Override |
| 11121 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11122 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11123 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11124 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11125 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11126 | final long identity = Binder.clearCallingIdentity(); |
| 11127 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11128 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11129 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11130 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11131 | return carrierUserAgent; |
| 11132 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11133 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11134 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11135 | } finally { |
| 11136 | Binder.restoreCallingIdentity(identity); |
| 11137 | } |
| 11138 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11139 | |
| 11140 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11141 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11142 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11143 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11144 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11145 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11146 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11147 | final long identity = Binder.clearCallingIdentity(); |
| 11148 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11149 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11150 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11151 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11152 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11153 | } finally { |
| 11154 | Binder.restoreCallingIdentity(identity); |
| 11155 | } |
| 11156 | } |
| 11157 | |
| 11158 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11159 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11160 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11161 | enforceModifyPermission(); |
| 11162 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11163 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11164 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11165 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11166 | final long identity = Binder.clearCallingIdentity(); |
| 11167 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11168 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11169 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11170 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11171 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11172 | } finally { |
| 11173 | Binder.restoreCallingIdentity(identity); |
| 11174 | } |
| 11175 | } |
| 11176 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11177 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11178 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11179 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11180 | * otherwise. |
| 11181 | */ |
| 11182 | @Override |
| 11183 | public void setCepEnabled(boolean isCepEnabled) { |
| 11184 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11185 | |
| 11186 | final long identity = Binder.clearCallingIdentity(); |
| 11187 | try { |
| 11188 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11189 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11190 | Phone defaultPhone = phone.getImsPhone(); |
| 11191 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11192 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11193 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11194 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11195 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11196 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11197 | + imsPhone.getMsisdn()); |
| 11198 | } |
| 11199 | } |
| 11200 | } finally { |
| 11201 | Binder.restoreCallingIdentity(identity); |
| 11202 | } |
| 11203 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11204 | |
| 11205 | /** |
| 11206 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11207 | * |
| 11208 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11209 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11210 | * before being read. |
| 11211 | */ |
| 11212 | @Override |
| 11213 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11214 | isCompressed) { |
| 11215 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11216 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11217 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11218 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11219 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11220 | |
| 11221 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11222 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11223 | Binder.getCallingUserHandle())) { |
| 11224 | if (!isImsAvailableOnDevice()) { |
| 11225 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11226 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11227 | throw new IllegalStateException("IMS not available on device."); |
| 11228 | } |
| 11229 | } else { |
| 11230 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11231 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11232 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11233 | } |
| 11234 | |
| 11235 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11236 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11237 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11238 | } finally { |
| 11239 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11240 | } |
| 11241 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11242 | |
| 11243 | @Override |
| 11244 | public boolean isIccLockEnabled(int subId) { |
| 11245 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11246 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11247 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11248 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11249 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11250 | // Now that all security checks passes, perform the operation as ourselves. |
| 11251 | final long identity = Binder.clearCallingIdentity(); |
| 11252 | try { |
| 11253 | Phone phone = getPhone(subId); |
| 11254 | if (phone != null && phone.getIccCard() != null) { |
| 11255 | return phone.getIccCard().getIccLockEnabled(); |
| 11256 | } else { |
| 11257 | return false; |
| 11258 | } |
| 11259 | } finally { |
| 11260 | Binder.restoreCallingIdentity(identity); |
| 11261 | } |
| 11262 | } |
| 11263 | |
| 11264 | /** |
| 11265 | * Set the ICC pin lock enabled or disabled. |
| 11266 | * |
| 11267 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11268 | * three cases: |
| 11269 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11270 | * successfully. |
| 11271 | * - Positive number and zero for remaining password attempts. |
| 11272 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11273 | * |
| 11274 | */ |
| 11275 | @Override |
| 11276 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11277 | enforceModifyPermission(); |
| 11278 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11279 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11280 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11281 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11282 | Phone phone = getPhone(subId); |
| 11283 | if (phone == null) { |
| 11284 | return 0; |
| 11285 | } |
| 11286 | // Now that all security checks passes, perform the operation as ourselves. |
| 11287 | final long identity = Binder.clearCallingIdentity(); |
| 11288 | try { |
| 11289 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11290 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11291 | return attemptsRemaining; |
| 11292 | |
| 11293 | } catch (Exception e) { |
| 11294 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11295 | } finally { |
| 11296 | Binder.restoreCallingIdentity(identity); |
| 11297 | } |
| 11298 | return 0; |
| 11299 | } |
| 11300 | |
| 11301 | /** |
| 11302 | * Change the ICC password used in ICC pin lock. |
| 11303 | * |
| 11304 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11305 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11306 | * - Positive number and zero for remaining password attempts. |
| 11307 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11308 | * |
| 11309 | */ |
| 11310 | @Override |
| 11311 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11312 | enforceModifyPermission(); |
| 11313 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11314 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11315 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11316 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11317 | Phone phone = getPhone(subId); |
| 11318 | if (phone == null) { |
| 11319 | return 0; |
| 11320 | } |
| 11321 | // Now that all security checks passes, perform the operation as ourselves. |
| 11322 | final long identity = Binder.clearCallingIdentity(); |
| 11323 | try { |
| 11324 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11325 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11326 | return attemptsRemaining; |
| 11327 | |
| 11328 | } catch (Exception e) { |
| 11329 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11330 | } finally { |
| 11331 | Binder.restoreCallingIdentity(identity); |
| 11332 | } |
| 11333 | return 0; |
| 11334 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11335 | |
| 11336 | /** |
| 11337 | * Request for receiving user activity notification |
| 11338 | */ |
| 11339 | @Override |
| 11340 | public void requestUserActivityNotification() { |
| 11341 | if (!mNotifyUserActivity.get() |
| 11342 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11343 | mNotifyUserActivity.set(true); |
| 11344 | } |
| 11345 | } |
| 11346 | |
| 11347 | /** |
| 11348 | * Called when userActivity is signalled in the power manager. |
| 11349 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11350 | */ |
| 11351 | @Override |
| 11352 | public void userActivity() { |
| 11353 | // *************************************** |
| 11354 | // * Inherited from PhoneWindowManager * |
| 11355 | // *************************************** |
| 11356 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11357 | // WITH ITS LOCKS HELD. |
| 11358 | // |
| 11359 | // This code must be VERY careful about the locks |
| 11360 | // it acquires. |
| 11361 | // In fact, the current code acquires way too many, |
| 11362 | // and probably has lurking deadlocks. |
| 11363 | |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 11364 | if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) { |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11365 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11366 | } |
| 11367 | |
| 11368 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11369 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11370 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11371 | } |
| 11372 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11373 | |
| 11374 | @Override |
| 11375 | public boolean canConnectTo5GInDsdsMode() { |
| 11376 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11377 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11378 | |
| 11379 | @Override |
| 11380 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11381 | String callingFeatureId) { |
| 11382 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11383 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11384 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11385 | } |
| 11386 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11387 | enforceTelephonyFeatureWithException(callingPackage, |
| 11388 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11389 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11390 | Phone phone = getPhone(subId); |
| 11391 | if (phone == null) { |
| 11392 | throw new RuntimeException("phone is not available"); |
| 11393 | } |
| 11394 | // Now that all security checks passes, perform the operation as ourselves. |
| 11395 | final long identity = Binder.clearCallingIdentity(); |
| 11396 | try { |
| 11397 | return phone.getEquivalentHomePlmns(); |
| 11398 | } finally { |
| 11399 | Binder.restoreCallingIdentity(identity); |
| 11400 | } |
| 11401 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11402 | |
| 11403 | @Override |
| 11404 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11405 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11406 | if (!mApp.getResources().getBoolean( |
| 11407 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11408 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11409 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11410 | "isRadioInterfaceCapabilitySupported"); |
| 11411 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11412 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11413 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11414 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11415 | if (radioInterfaceCapabilities == null) { |
| 11416 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11417 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11418 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11419 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11420 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11421 | @Override |
| 11422 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11423 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11424 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11425 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11426 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11427 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11428 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11429 | |
| 11430 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11431 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11432 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11433 | if (DBG) { |
| 11434 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11435 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11436 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11437 | } |
| 11438 | |
| 11439 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11440 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11441 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11442 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11443 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11444 | if (callback != null) { |
| 11445 | try { |
| 11446 | callback.onAuthenticationFailure( |
| 11447 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11448 | } catch (RemoteException exception) { |
| 11449 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11450 | } |
| 11451 | return; |
| 11452 | } |
| 11453 | } |
| 11454 | |
| 11455 | final long token = Binder.clearCallingIdentity(); |
| 11456 | try { |
| 11457 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11458 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11459 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11460 | } finally { |
| 11461 | Binder.restoreCallingIdentity(token); |
| 11462 | } |
| 11463 | } |
| 11464 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11465 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11466 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11467 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11468 | * requested radio power state will actually be set. See {@link |
| 11469 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11470 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11471 | * @param enable {@code true} if trying to turn radio on. |
| 11472 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11473 | * false}. |
| 11474 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11475 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11476 | boolean isPhoneAvailable = false; |
| 11477 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11478 | Phone phone = PhoneFactory.getPhone(i); |
| 11479 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11480 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11481 | isPhoneAvailable = true; |
| 11482 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11483 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11484 | |
| 11485 | // return true if successfully informed the phone object about the thermal radio power |
| 11486 | // request. |
| 11487 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11488 | } |
| 11489 | |
| 11490 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11491 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11492 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11493 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11494 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11495 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11496 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11497 | } |
| 11498 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11499 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11500 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11501 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11502 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11503 | } |
| 11504 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11505 | setDataEnabledForReason( |
| 11506 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11507 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11508 | if (isDataThrottlingSupported) { |
| 11509 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11510 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11511 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11512 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11513 | } else if (thermalMitigationResult |
| 11514 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11515 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11516 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11517 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11518 | } |
| 11519 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11520 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11521 | |
| 11522 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11523 | } |
| 11524 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11525 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11526 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11527 | for (String pckg : context.getResources() |
| 11528 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11529 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11530 | } |
| 11531 | } |
| 11532 | |
| 11533 | return sThermalMitigationAllowlistedPackages; |
| 11534 | } |
| 11535 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11536 | private boolean isAnyPhoneInEmergencyState() { |
| 11537 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11538 | if (tm.isInEmergencyCall()) { |
| 11539 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11540 | return true; |
| 11541 | } |
| 11542 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11543 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11544 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11545 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11546 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11547 | return true; |
| 11548 | } |
| 11549 | } |
| 11550 | |
| 11551 | return false; |
| 11552 | } |
| 11553 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11554 | /** |
| 11555 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11556 | * @param packageName name of package to be allowlisted |
| 11557 | * @param context |
| 11558 | */ |
| 11559 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11560 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11561 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11562 | } |
| 11563 | |
| 11564 | /** |
| 11565 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11566 | * @param packageName name of package to remove from allowlist |
| 11567 | * @param context |
| 11568 | */ |
| 11569 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11570 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11571 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11572 | } |
| 11573 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11574 | /** |
| 11575 | * Thermal mitigation request to control functionalities at modem. |
| 11576 | * |
| 11577 | * @param subId the id of the subscription. |
| 11578 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11579 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11580 | * |
| 11581 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11582 | */ |
| 11583 | @Override |
| 11584 | @ThermalMitigationResult |
| 11585 | public int sendThermalMitigationRequest( |
| 11586 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11587 | ThermalMitigationRequest thermalMitigationRequest, |
| 11588 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11589 | enforceModifyPermission(); |
| 11590 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11591 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11592 | |
| 11593 | enforceTelephonyFeatureWithException(callingPackage, |
| 11594 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11595 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11596 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11597 | .contains(callingPackage)) { |
| 11598 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11599 | + "calling package: " + callingPackage); |
| 11600 | } |
| 11601 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11602 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11603 | final long identity = Binder.clearCallingIdentity(); |
| 11604 | |
| 11605 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11606 | try { |
| 11607 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11608 | switch (thermalMitigationAction) { |
| 11609 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11610 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11611 | handleDataThrottlingRequest(subId, |
| 11612 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11613 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11614 | break; |
| 11615 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11616 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11617 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11618 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11619 | } |
| 11620 | |
| 11621 | // Ensure that radio is on. If not able to power on due to phone being |
| 11622 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11623 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11624 | thermalMitigationResult = |
| 11625 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11626 | break; |
| 11627 | } |
| 11628 | |
| 11629 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11630 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11631 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11632 | break; |
| 11633 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11634 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11635 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11636 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11637 | } |
| 11638 | |
| 11639 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11640 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11641 | Phone phone = getPhone(subId); |
| 11642 | if (phone == null) { |
| 11643 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11644 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11645 | break; |
| 11646 | } |
| 11647 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11648 | TelephonyConnectionService service = |
| 11649 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11650 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11651 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11652 | thermalMitigationResult = |
| 11653 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11654 | break; |
| 11655 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11656 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11657 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11658 | break; |
| 11659 | } |
| 11660 | } else { |
| 11661 | thermalMitigationResult = |
| 11662 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11663 | break; |
| 11664 | } |
| 11665 | |
| 11666 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11667 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11668 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11669 | thermalMitigationResult = |
| 11670 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11671 | break; |
| 11672 | } |
| 11673 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11674 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11675 | break; |
| 11676 | default: |
| 11677 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11678 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11679 | } |
| 11680 | } catch (IllegalArgumentException e) { |
| 11681 | throw e; |
| 11682 | } catch (Exception e) { |
| 11683 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11684 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11685 | } finally { |
| 11686 | Binder.restoreCallingIdentity(identity); |
| 11687 | } |
| 11688 | |
| 11689 | if (DBG) { |
| 11690 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11691 | + thermalMitigationResult); |
| 11692 | } |
| 11693 | |
| 11694 | return thermalMitigationResult; |
| 11695 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11696 | |
| 11697 | /** |
| 11698 | * Set the GbaService Package Name that Telephony will bind to. |
| 11699 | * |
| 11700 | * @param subId The sim that the GbaService is associated with. |
| 11701 | * @param packageName The name of the package to be replaced with. |
| 11702 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11703 | */ |
| 11704 | @Override |
| 11705 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11706 | enforceModifyPermission(); |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11707 | int userId = ActivityManager.getCurrentUser(); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11708 | final long identity = Binder.clearCallingIdentity(); |
| 11709 | try { |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11710 | return getGbaManager(subId).overrideServicePackage(packageName, userId); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11711 | } finally { |
| 11712 | Binder.restoreCallingIdentity(identity); |
| 11713 | } |
| 11714 | } |
| 11715 | |
| 11716 | /** |
| 11717 | * Return the package name of the currently bound GbaService. |
| 11718 | * |
| 11719 | * @param subId The sim that the GbaService is associated with. |
| 11720 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11721 | */ |
| 11722 | @Override |
| 11723 | public String getBoundGbaService(int subId) { |
| 11724 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11725 | |
| 11726 | final long identity = Binder.clearCallingIdentity(); |
| 11727 | try { |
| 11728 | return getGbaManager(subId).getServicePackage(); |
| 11729 | } finally { |
| 11730 | Binder.restoreCallingIdentity(identity); |
| 11731 | } |
| 11732 | } |
| 11733 | |
| 11734 | /** |
| 11735 | * Set the release time for telephony to unbind GbaService. |
| 11736 | * |
| 11737 | * @param subId The sim that the GbaService is associated with. |
| 11738 | * @param interval The release time to unbind GbaService by millisecond. |
| 11739 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11740 | */ |
| 11741 | @Override |
| 11742 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11743 | enforceModifyPermission(); |
| 11744 | |
| 11745 | final long identity = Binder.clearCallingIdentity(); |
| 11746 | try { |
| 11747 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11748 | } finally { |
| 11749 | Binder.restoreCallingIdentity(identity); |
| 11750 | } |
| 11751 | } |
| 11752 | |
| 11753 | /** |
| 11754 | * Return the release time for telephony to unbind GbaService. |
| 11755 | * |
| 11756 | * @param subId The sim that the GbaService is associated with. |
| 11757 | * @return The release time to unbind GbaService by millisecond. |
| 11758 | */ |
| 11759 | @Override |
| 11760 | public int getGbaReleaseTime(int subId) { |
| 11761 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11762 | |
| 11763 | final long identity = Binder.clearCallingIdentity(); |
| 11764 | try { |
| 11765 | return getGbaManager(subId).getReleaseTime(); |
| 11766 | } finally { |
| 11767 | Binder.restoreCallingIdentity(identity); |
| 11768 | } |
| 11769 | } |
| 11770 | |
| 11771 | private GbaManager getGbaManager(int subId) { |
| 11772 | GbaManager instance = GbaManager.getInstance(subId); |
| 11773 | if (instance == null) { |
| 11774 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11775 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11776 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11777 | } |
| 11778 | return instance; |
| 11779 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11780 | |
| 11781 | /** |
| 11782 | * indicate whether the device and the carrier can support |
| 11783 | * RCS VoLTE single registration. |
| 11784 | */ |
| 11785 | @Override |
| 11786 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11787 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11788 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11789 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11790 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11791 | |
| 11792 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11793 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11794 | } |
| 11795 | |
| 11796 | final long identity = Binder.clearCallingIdentity(); |
| 11797 | try { |
| 11798 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11799 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11800 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11801 | if (isCapable != null) { |
| 11802 | return isCapable; |
| 11803 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11804 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11805 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11806 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11807 | } finally { |
| 11808 | Binder.restoreCallingIdentity(identity); |
| 11809 | } |
| 11810 | } |
| 11811 | |
| 11812 | /** |
| 11813 | * Register RCS provisioning callback. |
| 11814 | */ |
| 11815 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11816 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11817 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11818 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11819 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11820 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11821 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11822 | |
| 11823 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11824 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11825 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11826 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11827 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11828 | Binder.getCallingUserHandle())) { |
| 11829 | if (!isImsAvailableOnDevice()) { |
| 11830 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11831 | "IMS not available on device."); |
| 11832 | } |
| 11833 | } else { |
| 11834 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11835 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11836 | } |
| 11837 | |
| 11838 | final long identity = Binder.clearCallingIdentity(); |
| 11839 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11840 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11841 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11842 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11843 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11844 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11845 | } finally { |
| 11846 | Binder.restoreCallingIdentity(identity); |
| 11847 | } |
| 11848 | } |
| 11849 | |
| 11850 | /** |
| 11851 | * Unregister RCS provisioning callback. |
| 11852 | */ |
| 11853 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11854 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11855 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11856 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11857 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11858 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11859 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11860 | |
| 11861 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11862 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11863 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11864 | |
| 11865 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11866 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11867 | Binder.getCallingUserHandle())) { |
| 11868 | if (!isImsAvailableOnDevice()) { |
| 11869 | // operation failed silently |
| 11870 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11871 | return; |
| 11872 | } |
| 11873 | } else { |
| 11874 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11875 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11876 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11877 | } |
| 11878 | |
| 11879 | final long identity = Binder.clearCallingIdentity(); |
| 11880 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11881 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11882 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11883 | } finally { |
| 11884 | Binder.restoreCallingIdentity(identity); |
| 11885 | } |
| 11886 | } |
| 11887 | |
| 11888 | /** |
| 11889 | * trigger RCS reconfiguration. |
| 11890 | */ |
| 11891 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11892 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11893 | "triggerRcsReconfiguration", |
| 11894 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11895 | |
| 11896 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11897 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11898 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11899 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11900 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11901 | Binder.getCallingUserHandle())) { |
| 11902 | if (!isImsAvailableOnDevice()) { |
| 11903 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11904 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11905 | throw new IllegalStateException("IMS not available on device."); |
| 11906 | } |
| 11907 | } else { |
| 11908 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11909 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11910 | } |
| 11911 | |
| 11912 | final long identity = Binder.clearCallingIdentity(); |
| 11913 | try { |
| 11914 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11915 | } finally { |
| 11916 | Binder.restoreCallingIdentity(identity); |
| 11917 | } |
| 11918 | } |
| 11919 | |
| 11920 | /** |
| 11921 | * Provide the client configuration parameters of the RCS application. |
| 11922 | */ |
| 11923 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11924 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11925 | "setRcsClientConfiguration", |
| 11926 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11927 | |
| 11928 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11929 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11930 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11931 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11932 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11933 | Binder.getCallingUserHandle())) { |
| 11934 | if (!isImsAvailableOnDevice()) { |
| 11935 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11936 | "IMS not available on device."); |
| 11937 | } |
| 11938 | } else { |
| 11939 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11940 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11941 | } |
| 11942 | |
| 11943 | final long identity = Binder.clearCallingIdentity(); |
| 11944 | |
| 11945 | try { |
| 11946 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11947 | if (configBinder == null) { |
| 11948 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11949 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11950 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11951 | } else { |
| 11952 | configBinder.setRcsClientConfiguration(rcc); |
| 11953 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11954 | |
| 11955 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11956 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11957 | } catch (RemoteException e) { |
| 11958 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11959 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11960 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11961 | } finally { |
| 11962 | Binder.restoreCallingIdentity(identity); |
| 11963 | } |
| 11964 | } |
| 11965 | |
| 11966 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11967 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11968 | */ |
| 11969 | @Override |
| 11970 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11971 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11972 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11973 | |
| 11974 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11975 | } |
| 11976 | |
| 11977 | /** |
| 11978 | * Gets the test mode for RCS VoLTE single registration. |
| 11979 | */ |
| 11980 | @Override |
| 11981 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11982 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11983 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11984 | |
| 11985 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11986 | } |
| 11987 | |
| 11988 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11989 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11990 | */ |
| 11991 | @Override |
| 11992 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11993 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11994 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11995 | enforceModifyPermission(); |
| 11996 | |
| 11997 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11998 | : Boolean.parseBoolean(enabledStr); |
| 11999 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 12000 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12001 | } |
| 12002 | |
| 12003 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12004 | * Sends a device to device communication message. Only usable via shell. |
| 12005 | * @param message message to send. |
| 12006 | * @param value message value. |
| 12007 | */ |
| 12008 | @Override |
| 12009 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 12010 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12011 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12012 | enforceModifyPermission(); |
| 12013 | |
| 12014 | final long identity = Binder.clearCallingIdentity(); |
| 12015 | try { |
| 12016 | TelephonyConnectionService service = |
| 12017 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12018 | if (service == null) { |
| 12019 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 12020 | return; |
| 12021 | } |
| 12022 | service.sendTestDeviceToDeviceMessage(message, value); |
| 12023 | } finally { |
| 12024 | Binder.restoreCallingIdentity(identity); |
| 12025 | } |
| 12026 | } |
| 12027 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12028 | /** |
| 12029 | * Sets the specified device to device transport active. |
| 12030 | * @param transport The transport to set active. |
| 12031 | */ |
| 12032 | @Override |
| 12033 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 12034 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12035 | "setActiveDeviceToDeviceTransport"); |
| 12036 | enforceModifyPermission(); |
| 12037 | |
| 12038 | final long identity = Binder.clearCallingIdentity(); |
| 12039 | try { |
| 12040 | TelephonyConnectionService service = |
| 12041 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12042 | if (service == null) { |
| 12043 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 12044 | return; |
| 12045 | } |
| 12046 | service.setActiveDeviceToDeviceTransport(transport); |
| 12047 | } finally { |
| 12048 | Binder.restoreCallingIdentity(identity); |
| 12049 | } |
| 12050 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12051 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12052 | @Override |
| 12053 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12054 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12055 | "setDeviceToDeviceForceEnabled"); |
| 12056 | |
| 12057 | final long identity = Binder.clearCallingIdentity(); |
| 12058 | try { |
| 12059 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12060 | p -> { |
| 12061 | Phone thePhone = p.getImsPhone(); |
| 12062 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12063 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12064 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12065 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12066 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12067 | (ImsPhoneCallTracker) tracker; |
| 12068 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12069 | } |
| 12070 | } |
| 12071 | } |
| 12072 | ); |
| 12073 | } finally { |
| 12074 | Binder.restoreCallingIdentity(identity); |
| 12075 | } |
| 12076 | } |
| 12077 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12078 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12079 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12080 | */ |
| 12081 | @Override |
| 12082 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12083 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12084 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12085 | } |
| 12086 | |
| 12087 | /** |
| 12088 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12089 | */ |
| 12090 | @Override |
| 12091 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12092 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12093 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12094 | enforceModifyPermission(); |
| 12095 | |
| 12096 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12097 | : Boolean.parseBoolean(enabledStr); |
| 12098 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12099 | subId, enabled); |
| 12100 | } |
| 12101 | |
| 12102 | /** |
| 12103 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12104 | */ |
| 12105 | @Override |
| 12106 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12107 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12108 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12109 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12110 | |
| 12111 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12112 | * Overrides the ims feature validation result |
| 12113 | */ |
| 12114 | @Override |
| 12115 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12116 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12117 | "setImsFeatureValidationOverride"); |
| 12118 | |
| 12119 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12120 | : Boolean.parseBoolean(enabledStr); |
| 12121 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12122 | subId, enabled); |
| 12123 | } |
| 12124 | |
| 12125 | /** |
| 12126 | * Gets the ims feature validation override value |
| 12127 | */ |
| 12128 | @Override |
| 12129 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12130 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12131 | "getImsFeatureValidationOverride"); |
| 12132 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12133 | } |
| 12134 | |
| 12135 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12136 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12137 | * their mobile plan. |
| 12138 | */ |
| 12139 | @Override |
| 12140 | public String getMobileProvisioningUrl() { |
| 12141 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12142 | final long identity = Binder.clearCallingIdentity(); |
| 12143 | try { |
| 12144 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12145 | } finally { |
| 12146 | Binder.restoreCallingIdentity(identity); |
| 12147 | } |
| 12148 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12149 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12150 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12151 | * Get the EAB contact from the EAB database. |
| 12152 | */ |
| 12153 | @Override |
| 12154 | public String getContactFromEab(String contact) { |
| 12155 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12156 | enforceModifyPermission(); |
| 12157 | final long identity = Binder.clearCallingIdentity(); |
| 12158 | try { |
| 12159 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12160 | } finally { |
| 12161 | Binder.restoreCallingIdentity(identity); |
| 12162 | } |
| 12163 | } |
| 12164 | |
| 12165 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12166 | * Get the EAB capability from the EAB database. |
| 12167 | */ |
| 12168 | @Override |
| 12169 | public String getCapabilityFromEab(String contact) { |
| 12170 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12171 | enforceModifyPermission(); |
| 12172 | final long identity = Binder.clearCallingIdentity(); |
| 12173 | try { |
| 12174 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12175 | } finally { |
| 12176 | Binder.restoreCallingIdentity(identity); |
| 12177 | } |
| 12178 | } |
| 12179 | |
| 12180 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12181 | * Remove the EAB contacts from the EAB database. |
| 12182 | */ |
| 12183 | @Override |
| 12184 | public int removeContactFromEab(int subId, String contacts) { |
| 12185 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12186 | enforceModifyPermission(); |
| 12187 | final long identity = Binder.clearCallingIdentity(); |
| 12188 | try { |
| 12189 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12190 | } finally { |
| 12191 | Binder.restoreCallingIdentity(identity); |
| 12192 | } |
| 12193 | } |
| 12194 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12195 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12196 | public boolean getDeviceUceEnabled() { |
| 12197 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12198 | final long identity = Binder.clearCallingIdentity(); |
| 12199 | try { |
| 12200 | return mApp.getDeviceUceEnabled(); |
| 12201 | } finally { |
| 12202 | Binder.restoreCallingIdentity(identity); |
| 12203 | } |
| 12204 | } |
| 12205 | |
| 12206 | @Override |
| 12207 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12208 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12209 | final long identity = Binder.clearCallingIdentity(); |
| 12210 | try { |
| 12211 | mApp.setDeviceUceEnabled(isEnabled); |
| 12212 | } finally { |
| 12213 | Binder.restoreCallingIdentity(identity); |
| 12214 | } |
| 12215 | } |
| 12216 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12217 | /** |
| 12218 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12219 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12220 | */ |
| 12221 | // Used for SHELL command only right now. |
| 12222 | @Override |
| 12223 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12224 | List<String> featureTags) { |
| 12225 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12226 | "addUceRegistrationOverrideShell"); |
| 12227 | final long identity = Binder.clearCallingIdentity(); |
| 12228 | try { |
| 12229 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12230 | new ArraySet<>(featureTags)); |
| 12231 | } catch (ImsException e) { |
| 12232 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12233 | } finally { |
| 12234 | Binder.restoreCallingIdentity(identity); |
| 12235 | } |
| 12236 | } |
| 12237 | |
| 12238 | /** |
| 12239 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12240 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12241 | */ |
| 12242 | // Used for SHELL command only right now. |
| 12243 | @Override |
| 12244 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12245 | List<String> featureTags) { |
| 12246 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12247 | "removeUceRegistrationOverrideShell"); |
| 12248 | final long identity = Binder.clearCallingIdentity(); |
| 12249 | try { |
| 12250 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12251 | new ArraySet<>(featureTags)); |
| 12252 | } catch (ImsException e) { |
| 12253 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12254 | } finally { |
| 12255 | Binder.restoreCallingIdentity(identity); |
| 12256 | } |
| 12257 | } |
| 12258 | |
| 12259 | /** |
| 12260 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12261 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12262 | */ |
| 12263 | // Used for SHELL command only right now. |
| 12264 | @Override |
| 12265 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12266 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12267 | "clearUceRegistrationOverrideShell"); |
| 12268 | final long identity = Binder.clearCallingIdentity(); |
| 12269 | try { |
| 12270 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12271 | } catch (ImsException e) { |
| 12272 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12273 | } finally { |
| 12274 | Binder.restoreCallingIdentity(identity); |
| 12275 | } |
| 12276 | } |
| 12277 | |
| 12278 | /** |
| 12279 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12280 | */ |
| 12281 | // Used for SHELL command only right now. |
| 12282 | @Override |
| 12283 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12284 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12285 | "getLatestRcsContactUceCapabilityShell"); |
| 12286 | final long identity = Binder.clearCallingIdentity(); |
| 12287 | try { |
| 12288 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12289 | } catch (ImsException e) { |
| 12290 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12291 | } finally { |
| 12292 | Binder.restoreCallingIdentity(identity); |
| 12293 | } |
| 12294 | } |
| 12295 | |
| 12296 | /** |
| 12297 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12298 | * device does not have an active PUBLISH. |
| 12299 | */ |
| 12300 | // Used for SHELL command only right now. |
| 12301 | @Override |
| 12302 | public String getLastUcePidfXmlShell(int subId) { |
| 12303 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12304 | final long identity = Binder.clearCallingIdentity(); |
| 12305 | try { |
| 12306 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12307 | } catch (ImsException e) { |
| 12308 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12309 | } finally { |
| 12310 | Binder.restoreCallingIdentity(identity); |
| 12311 | } |
| 12312 | } |
| 12313 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12314 | /** |
| 12315 | * Remove UCE requests cannot be sent to the network status. |
| 12316 | */ |
| 12317 | // Used for SHELL command only right now. |
| 12318 | @Override |
| 12319 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12320 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12321 | final long identity = Binder.clearCallingIdentity(); |
| 12322 | try { |
| 12323 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12324 | } catch (ImsException e) { |
| 12325 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12326 | } finally { |
| 12327 | Binder.restoreCallingIdentity(identity); |
| 12328 | } |
| 12329 | } |
| 12330 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12331 | /** |
| 12332 | * Remove UCE requests cannot be sent to the network status. |
| 12333 | */ |
| 12334 | // Used for SHELL command only. |
| 12335 | @Override |
| 12336 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12337 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12338 | final long identity = Binder.clearCallingIdentity(); |
| 12339 | try { |
| 12340 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12341 | } catch (ImsException e) { |
| 12342 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12343 | } finally { |
| 12344 | Binder.restoreCallingIdentity(identity); |
| 12345 | } |
| 12346 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12347 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12348 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12349 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12350 | String callingPackage) { |
| 12351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12352 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12353 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12354 | enforceTelephonyFeatureWithException(callingPackage, |
| 12355 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12356 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12357 | final int callingUid = Binder.getCallingUid(); |
| 12358 | // Verify that tha callingPackage belongs to the calling UID |
| 12359 | mApp.getSystemService(AppOpsManager.class) |
| 12360 | .checkPackage(callingUid, callingPackage); |
| 12361 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12362 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12363 | |
| 12364 | final long identity = Binder.clearCallingIdentity(); |
| 12365 | try { |
| 12366 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12367 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12368 | |
| 12369 | if (result instanceof IllegalStateException) { |
| 12370 | throw (IllegalStateException) result; |
| 12371 | } |
| 12372 | } finally { |
| 12373 | Binder.restoreCallingIdentity(identity); |
| 12374 | } |
| 12375 | } |
| 12376 | |
| 12377 | @Override |
| 12378 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12379 | String callingPackage) { |
| 12380 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12381 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12382 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12383 | enforceTelephonyFeatureWithException(callingPackage, |
| 12384 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12385 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12386 | final int callingUid = Binder.getCallingUid(); |
| 12387 | // Verify that tha callingPackage belongs to the calling UID |
| 12388 | mApp.getSystemService(AppOpsManager.class) |
| 12389 | .checkPackage(callingUid, callingPackage); |
| 12390 | |
| 12391 | final long identity = Binder.clearCallingIdentity(); |
| 12392 | try { |
| 12393 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12394 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12395 | |
| 12396 | if (result instanceof IllegalStateException) { |
| 12397 | throw (IllegalStateException) result; |
| 12398 | } |
| 12399 | } finally { |
| 12400 | Binder.restoreCallingIdentity(identity); |
| 12401 | } |
| 12402 | } |
| 12403 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12404 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12405 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12406 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12407 | // phone/system process do not have further restriction on request |
| 12408 | return; |
| 12409 | } |
| 12410 | |
| 12411 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12412 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12413 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12414 | context.enforceCallingOrSelfPermission( |
| 12415 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12416 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12417 | } |
| 12418 | |
| 12419 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12420 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12421 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12422 | || info.isEnabled()) { |
| 12423 | throw new IllegalArgumentException( |
| 12424 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12425 | } |
| 12426 | |
| 12427 | // Thresholds length for each RAN need in range. This has been validated in |
| 12428 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12429 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12430 | final int[] thresholds = info.getThresholds(); |
| 12431 | Objects.requireNonNull(thresholds); |
| 12432 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12433 | || thresholds.length |
| 12434 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12435 | throw new IllegalArgumentException( |
| 12436 | "thresholds length is out of range: " + thresholds.length); |
| 12437 | } |
| 12438 | } |
| 12439 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12440 | |
| 12441 | /** |
| 12442 | * Gets the current phone capability. |
| 12443 | * |
| 12444 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12445 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12446 | * It's used to evaluate possible phone config change, for example from single |
| 12447 | * SIM device to multi-SIM device. |
| 12448 | */ |
| 12449 | @Override |
| 12450 | public PhoneCapability getPhoneCapability() { |
| 12451 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12452 | |
| 12453 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12454 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12455 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12456 | final long identity = Binder.clearCallingIdentity(); |
| 12457 | try { |
| 12458 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12459 | } finally { |
| 12460 | Binder.restoreCallingIdentity(identity); |
| 12461 | } |
| 12462 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12463 | |
| 12464 | /** |
| 12465 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12466 | * required to be done shortly after the API is invoked. |
| 12467 | */ |
| 12468 | @Override |
| 12469 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12470 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12471 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12472 | enforceRebootPermission(); |
| 12473 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12474 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12475 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12476 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12477 | final long identity = Binder.clearCallingIdentity(); |
| 12478 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12479 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12480 | } finally { |
| 12481 | Binder.restoreCallingIdentity(identity); |
| 12482 | } |
| 12483 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12484 | |
| 12485 | /** |
| 12486 | * Request to get the current slicing configuration including URSP rules and |
| 12487 | * NSSAIs (configured, allowed and rejected). |
| 12488 | * |
| 12489 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12490 | */ |
| 12491 | @Override |
| 12492 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12493 | TelephonyPermissions |
| 12494 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12495 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12496 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12497 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12498 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12499 | "getSlicingConfig"); |
| 12500 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12501 | final long identity = Binder.clearCallingIdentity(); |
| 12502 | try { |
| 12503 | Phone phone = getDefaultPhone(); |
| 12504 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12505 | } finally { |
| 12506 | Binder.restoreCallingIdentity(identity); |
| 12507 | } |
| 12508 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12509 | |
| 12510 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12511 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12512 | * |
| 12513 | * @param capability The premium capability to check. |
| 12514 | * @param subId The subId to check the premium capability for. |
| 12515 | * |
| 12516 | * @return Whether the given premium capability is available to purchase. |
| 12517 | */ |
| 12518 | @Override |
| 12519 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12520 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12521 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12522 | log("Premium capability " |
| 12523 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12524 | + " is not available for purchase due to missing permissions."); |
| 12525 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12526 | + "permission READ_BASIC_PHONE_STATE."); |
| 12527 | } |
| 12528 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12529 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12530 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12531 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12532 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12533 | if (phone == null) { |
| 12534 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12535 | return false; |
| 12536 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12537 | final long identity = Binder.clearCallingIdentity(); |
| 12538 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12539 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12540 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12541 | } finally { |
| 12542 | Binder.restoreCallingIdentity(identity); |
| 12543 | } |
| 12544 | } |
| 12545 | |
| 12546 | /** |
| 12547 | * Purchase the given premium capability from the carrier. |
| 12548 | * |
| 12549 | * @param capability The premium capability to purchase. |
| 12550 | * @param callback The result of the purchase request. |
| 12551 | * @param subId The subId to purchase the premium capability for. |
| 12552 | */ |
| 12553 | @Override |
| 12554 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12555 | log("purchasePremiumCapability: capability=" |
| 12556 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12557 | + getCurrentPackageName()); |
| 12558 | |
| 12559 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12560 | mApp, "purchasePremiumCapability")) { |
| 12561 | log("purchasePremiumCapability " |
| 12562 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12563 | + " failed due to missing permissions."); |
| 12564 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12565 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12566 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12567 | mApp, "purchasePremiumCapability")) { |
| 12568 | log("purchasePremiumCapability " |
| 12569 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12570 | + " failed due to missing permissions."); |
| 12571 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12572 | } |
| 12573 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12574 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12575 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12576 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12577 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12578 | if (phone == null) { |
| 12579 | try { |
| 12580 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12581 | callback.accept(result); |
| 12582 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12583 | } catch (RemoteException e) { |
| 12584 | String logStr = "Purchase premium capability " |
| 12585 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12586 | + " failed due to RemoteException handling null phone: " + e; |
| 12587 | if (DBG) log(logStr); |
| 12588 | AnomalyReporter.reportAnomaly( |
| 12589 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12590 | } |
| 12591 | return; |
| 12592 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12593 | |
| 12594 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12595 | try { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 12596 | if (mFeatureFlags.hsumPackageManager()) { |
| 12597 | callingProcess = mApp.getPackageManager().getApplicationInfoAsUser( |
| 12598 | getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName; |
| 12599 | } else { |
| 12600 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12601 | getCurrentPackageName(), 0).processName; |
| 12602 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12603 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12604 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12605 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12606 | |
| 12607 | boolean isVisible = false; |
| 12608 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12609 | if (am != null) { |
| 12610 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12611 | if (processes != null) { |
| 12612 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12613 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12614 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12615 | if (process.processName.equals(callingProcess) && process.importance |
| 12616 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12617 | isVisible = true; |
| 12618 | break; |
| 12619 | } |
| 12620 | } |
| 12621 | } |
| 12622 | } |
| 12623 | |
| 12624 | if (!isVisible) { |
| 12625 | try { |
| 12626 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12627 | callback.accept(result); |
| 12628 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12629 | } catch (RemoteException e) { |
| 12630 | String logStr = "Purchase premium capability " |
| 12631 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12632 | + " failed due to RemoteException handling background application: " + e; |
| 12633 | if (DBG) log(logStr); |
| 12634 | AnomalyReporter.reportAnomaly( |
| 12635 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12636 | } |
| 12637 | return; |
| 12638 | } |
| 12639 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12640 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12641 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12642 | } |
| 12643 | |
| 12644 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12645 | * Register an IMS connection state callback |
| 12646 | */ |
| 12647 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12648 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12649 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12650 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12651 | // ImsMmTelManager |
| 12652 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12653 | TelephonyPermissions |
| 12654 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12655 | mApp, subId, "registerImsStateCallback"); |
| 12656 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12657 | // ImsRcsManager or SipDelegateManager |
| 12658 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12659 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12660 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12661 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12662 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12663 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12664 | } |
| 12665 | |
| 12666 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12667 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12668 | "IMS not available on device."); |
| 12669 | } |
| 12670 | |
| 12671 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12672 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12673 | } |
| 12674 | |
| 12675 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12676 | if (controller == null) { |
| 12677 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12678 | "IMS not available on device."); |
| 12679 | } |
| 12680 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12681 | if (callingPackage == null) { |
| 12682 | callingPackage = getCurrentPackageName(); |
| 12683 | } |
| 12684 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12685 | final long token = Binder.clearCallingIdentity(); |
| 12686 | try { |
| 12687 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12688 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12689 | } catch (ImsException e) { |
| 12690 | throw new ServiceSpecificException(e.getCode()); |
| 12691 | } finally { |
| 12692 | Binder.restoreCallingIdentity(token); |
| 12693 | } |
| 12694 | } |
| 12695 | |
| 12696 | /** |
| 12697 | * Unregister an IMS connection state callback |
| 12698 | */ |
| 12699 | @Override |
| 12700 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12701 | final long token = Binder.clearCallingIdentity(); |
| 12702 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12703 | if (controller == null) { |
| 12704 | return; |
| 12705 | } |
| 12706 | try { |
| 12707 | controller.unregisterImsStateCallback(cb); |
| 12708 | } finally { |
| 12709 | Binder.restoreCallingIdentity(token); |
| 12710 | } |
| 12711 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12712 | |
| 12713 | /** |
| 12714 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12715 | * |
| 12716 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12717 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12718 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12719 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12720 | * If there is current registered network this value will be same as the registered cell |
| 12721 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12722 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12723 | * it will be cleared and null will be returned. |
| 12724 | * |
| 12725 | */ |
| 12726 | @Override |
| 12727 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12728 | String callingFeatureId) { |
| 12729 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12730 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12731 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12732 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12733 | .setCallingPackage(callingPackage) |
| 12734 | .setCallingFeatureId(callingFeatureId) |
| 12735 | .setCallingPid(Binder.getCallingPid()) |
| 12736 | .setCallingUid(Binder.getCallingUid()) |
| 12737 | .setMethod("getLastKnownCellIdentity") |
| 12738 | .setLogAsInfo(true) |
| 12739 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12740 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12741 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12742 | .build()); |
| 12743 | |
| 12744 | boolean hasFinePermission = |
| 12745 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12746 | if (!hasFinePermission |
| 12747 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12748 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12749 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12750 | } |
| 12751 | |
| 12752 | final long identity = Binder.clearCallingIdentity(); |
| 12753 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12754 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12755 | if (sst == null) return null; |
| 12756 | return sst.getLastKnownCellIdentity(); |
| 12757 | } finally { |
| 12758 | Binder.restoreCallingIdentity(identity); |
| 12759 | } |
| 12760 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12761 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12762 | /** |
| 12763 | * Sets the modem service class Name that Telephony will bind to. |
| 12764 | * |
| 12765 | * @param serviceName The class name of the modem service. |
| 12766 | * @return true if the operation is succeed, otherwise false. |
| 12767 | */ |
| 12768 | public boolean setModemService(String serviceName) { |
| 12769 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12770 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12771 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12772 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12773 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12774 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12775 | } |
| 12776 | |
| 12777 | /** |
| 12778 | * Return the class name of the currently bounded modem service. |
| 12779 | * |
| 12780 | * @return the class name of the modem service. |
| 12781 | */ |
| 12782 | public String getModemService() { |
| 12783 | String result; |
| 12784 | Log.d(LOG_TAG, "getModemService"); |
| 12785 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12786 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12787 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12788 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12789 | "getModemService"); |
| 12790 | result = mPhoneConfigurationManager.getModemService(); |
| 12791 | Log.d(LOG_TAG, "result = " + result); |
| 12792 | return result; |
| 12793 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12794 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12795 | /** |
| 12796 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12797 | * including carrier config, entitlement server, and config update. |
| 12798 | * |
| 12799 | * @param subId subId The subscription ID of the carrier. |
| 12800 | * |
| 12801 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12802 | * be returned. |
| 12803 | * |
| 12804 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12805 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12806 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12807 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12808 | final long identity = Binder.clearCallingIdentity(); |
| 12809 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12810 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12811 | } finally { |
| 12812 | Binder.restoreCallingIdentity(identity); |
| 12813 | } |
| 12814 | } |
| 12815 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12816 | @Override |
| 12817 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12818 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12819 | mApp.enforceCallingOrSelfPermission( |
| 12820 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12821 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12822 | |
| 12823 | final long identity = Binder.clearCallingIdentity(); |
| 12824 | try { |
| 12825 | Phone phone = getPhone(subId); |
| 12826 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12827 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12828 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12829 | phone.setVoiceServiceStateOverride(hasService); |
| 12830 | } finally { |
| 12831 | Binder.restoreCallingIdentity(identity); |
| 12832 | } |
| 12833 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12834 | |
| 12835 | /** |
| 12836 | * set removable eSIM as default eUICC. |
| 12837 | * |
| 12838 | * @hide |
| 12839 | */ |
| 12840 | @Override |
| 12841 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12842 | enforceModifyPermission(); |
| 12843 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12844 | |
| 12845 | final long identity = Binder.clearCallingIdentity(); |
| 12846 | try { |
| 12847 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12848 | } finally { |
| 12849 | Binder.restoreCallingIdentity(identity); |
| 12850 | } |
| 12851 | } |
| 12852 | |
| 12853 | /** |
| 12854 | * Returns whether the removable eSIM is default eUICC or not. |
| 12855 | * |
| 12856 | * @hide |
| 12857 | */ |
| 12858 | @Override |
| 12859 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12860 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12861 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12862 | |
| 12863 | final long identity = Binder.clearCallingIdentity(); |
| 12864 | try { |
| 12865 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12866 | } finally { |
| 12867 | Binder.restoreCallingIdentity(identity); |
| 12868 | } |
| 12869 | } |
| 12870 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12871 | /** |
| 12872 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12873 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12874 | * application currently configured for this user. |
| 12875 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12876 | * {@code null} if the functionality is not supported. |
| 12877 | * @hide |
| 12878 | */ |
| 12879 | @Override |
| 12880 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12881 | boolean updateIfNeeded) { |
| 12882 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12883 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12884 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12885 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12886 | "getDefaultRespondViaMessageApplication"); |
| 12887 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12888 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12889 | |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12890 | if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){ |
| 12891 | UserHandle mainUser = null; |
| 12892 | Context userContext = null; |
| 12893 | final long identity = Binder.clearCallingIdentity(); |
| 12894 | try { |
| 12895 | mainUser = mUserManager.getMainUser(); |
| 12896 | userContext = context.createContextAsUser(mainUser, 0); |
| 12897 | Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser); |
| 12898 | } finally { |
| 12899 | Binder.restoreCallingIdentity(identity); |
| 12900 | } |
| 12901 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext, |
| 12902 | updateIfNeeded, mainUser); |
| 12903 | } else { |
| 12904 | UserHandle userHandle = null; |
| 12905 | final long identity = Binder.clearCallingIdentity(); |
| 12906 | try { |
| 12907 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12908 | } finally { |
| 12909 | Binder.restoreCallingIdentity(identity); |
| 12910 | } |
| 12911 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12912 | updateIfNeeded, userHandle); |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12913 | } |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12914 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12915 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12916 | |
| 12917 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12918 | * Set whether the device is able to connect with null ciphering or integrity |
| 12919 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12920 | * and all new subscriptions after this. |
| 12921 | * |
| 12922 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12923 | * @hide |
| 12924 | */ |
| 12925 | @Override |
| 12926 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12927 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12928 | enforceModifyPermission(); |
| 12929 | checkForNullCipherAndIntegritySupport(); |
| 12930 | |
| 12931 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12932 | // for listening to these preference changes and applying them immediately. |
| 12933 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12934 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12935 | editor.apply(); |
| 12936 | |
| 12937 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12938 | phone.handleNullCipherEnabledChange(); |
| 12939 | } |
| 12940 | } |
| 12941 | |
| 12942 | |
| 12943 | /** |
| 12944 | * Get whether the device is able to connect with null ciphering or integrity |
| 12945 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12946 | * the state of the radio. |
| 12947 | * |
| 12948 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12949 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12950 | * version for this feature. |
| 12951 | * @hide |
| 12952 | */ |
| 12953 | @Override |
| 12954 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12955 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12956 | enforceReadPermission(); |
| 12957 | checkForNullCipherAndIntegritySupport(); |
| 12958 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12959 | } |
| 12960 | |
| 12961 | private void checkForNullCipherAndIntegritySupport() { |
| 12962 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12963 | throw new UnsupportedOperationException( |
| 12964 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12965 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12966 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12967 | throw new UnsupportedOperationException( |
| 12968 | "Null cipher and integrity operations unsupported by modem"); |
| 12969 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12970 | } |
| 12971 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12972 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12973 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12974 | throw new UnsupportedOperationException( |
| 12975 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12976 | + "above"); |
| 12977 | } |
| 12978 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12979 | throw new UnsupportedOperationException( |
| 12980 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12981 | } |
| 12982 | } |
| 12983 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12984 | private void checkForNullCipherNotificationSupport() { |
| 12985 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12986 | throw new UnsupportedOperationException( |
| 12987 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12988 | } |
| 12989 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12990 | throw new UnsupportedOperationException( |
| 12991 | "Null cipher notification operations unsupported by modem"); |
| 12992 | } |
| 12993 | } |
| 12994 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12995 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12996 | * Get the SIM state for the slot index. |
| 12997 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12998 | * |
| 12999 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 13000 | */ |
| 13001 | @Override |
| 13002 | @SimState |
| 13003 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 13004 | if (!mApp.getResources().getBoolean( |
| 13005 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 13006 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13007 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 13008 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13009 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 13010 | IccCardConstants.State simState; |
| 13011 | if (slotIndex < 0) { |
| 13012 | simState = IccCardConstants.State.UNKNOWN; |
| 13013 | } else { |
| 13014 | Phone phone = null; |
| 13015 | try { |
| 13016 | phone = PhoneFactory.getPhone(slotIndex); |
| 13017 | } catch (IllegalStateException e) { |
| 13018 | // ignore |
| 13019 | } |
| 13020 | if (phone == null) { |
| 13021 | simState = IccCardConstants.State.UNKNOWN; |
| 13022 | } else { |
| 13023 | IccCard icc = phone.getIccCard(); |
| 13024 | if (icc == null) { |
| 13025 | simState = IccCardConstants.State.UNKNOWN; |
| 13026 | } else { |
| 13027 | simState = icc.getState(); |
| 13028 | } |
| 13029 | } |
| 13030 | } |
| 13031 | return simState.ordinal(); |
| 13032 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13033 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13034 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 13035 | boolean enableLogcat, |
| 13036 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13037 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13038 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13039 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 13040 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 13041 | ecdDataBuilder |
| 13042 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 13043 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13044 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13045 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13046 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13047 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 13048 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13049 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 13050 | Executors.newCachedThreadPool(), db, |
| 13051 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13052 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13053 | } |
| 13054 | |
| 13055 | /** |
| 13056 | * Request telephony to persist state for debugging emergency call failures. |
| 13057 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13058 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13059 | * @param enableLogcat whether to collect logcat output |
| 13060 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 13061 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 13062 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 13063 | */ |
| 13064 | @Override |
| 13065 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13066 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13067 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13068 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13069 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13070 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13071 | && Flags.enableReadDropboxPermission()) { |
| 13072 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13073 | "persistEmergencyCallDiagnosticData"); |
| 13074 | } else { |
| 13075 | // Otherwise, enforce legacy permission. |
| 13076 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13077 | "persistEmergencyCallDiagnosticData"); |
| 13078 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13079 | final long identity = Binder.clearCallingIdentity(); |
| 13080 | try { |
| 13081 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13082 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13083 | |
| 13084 | } finally { |
| 13085 | Binder.restoreCallingIdentity(identity); |
| 13086 | } |
| 13087 | } |
| 13088 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13089 | /** |
| 13090 | * Get current cell broadcast ranges. |
| 13091 | */ |
| 13092 | @Override |
| 13093 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13094 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13095 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13096 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13097 | |
| 13098 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13099 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13100 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13101 | final long identity = Binder.clearCallingIdentity(); |
| 13102 | try { |
| 13103 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13104 | } finally { |
| 13105 | Binder.restoreCallingIdentity(identity); |
| 13106 | } |
| 13107 | } |
| 13108 | |
| 13109 | /** |
| 13110 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13111 | * |
| 13112 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13113 | */ |
| 13114 | @Override |
| 13115 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13116 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13117 | @Nullable IIntegerConsumer callback) { |
| 13118 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13119 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13120 | |
| 13121 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13122 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13123 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13124 | final long identity = Binder.clearCallingIdentity(); |
| 13125 | try { |
| 13126 | Phone phone = getPhoneFromSubId(subId); |
| 13127 | if (DBG) { |
| 13128 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13129 | } |
| 13130 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13131 | if (callback != null) { |
| 13132 | try { |
| 13133 | callback.accept(result); |
| 13134 | } catch (RemoteException e) { |
| 13135 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13136 | } |
| 13137 | } |
| 13138 | }); |
| 13139 | } finally { |
| 13140 | Binder.restoreCallingIdentity(identity); |
| 13141 | } |
| 13142 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13143 | |
| 13144 | /** |
| 13145 | * Returns whether the device supports the domain selection service. |
| 13146 | * |
| 13147 | * @return {@code true} if the device supports the domain selection service. |
| 13148 | */ |
| 13149 | @Override |
| 13150 | public boolean isDomainSelectionSupported() { |
| 13151 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13152 | "isDomainSelectionSupported"); |
| 13153 | |
| 13154 | final long identity = Binder.clearCallingIdentity(); |
| 13155 | try { |
| 13156 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13157 | } finally { |
| 13158 | Binder.restoreCallingIdentity(identity); |
| 13159 | } |
| 13160 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13161 | |
| 13162 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13163 | * Returns whether the AOSP domain selection service is supported. |
| 13164 | * |
| 13165 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13166 | * {@code false} otherwise. |
| 13167 | */ |
| 13168 | @Override |
| 13169 | public boolean isAospDomainSelectionService() { |
| 13170 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13171 | "isAospDomainSelectionService"); |
| 13172 | |
| 13173 | final long identity = Binder.clearCallingIdentity(); |
| 13174 | try { |
| 13175 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13176 | String dssComponentName = mApp.getResources().getString( |
| 13177 | R.string.config_domain_selection_service_component_name); |
| 13178 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13179 | TelephonyDomainSelectionService.class.getName()); |
| 13180 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13181 | + ", aosp=" + componentName.flattenToString()); |
| 13182 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13183 | } |
| 13184 | } finally { |
| 13185 | Binder.restoreCallingIdentity(identity); |
| 13186 | } |
| 13187 | return false; |
| 13188 | } |
| 13189 | |
| 13190 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13191 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13192 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13193 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13194 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13195 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13196 | * {@code false} to disable. |
| 13197 | * @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] | 13198 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13199 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13200 | * |
| 13201 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13202 | */ |
| 13203 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13204 | public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13205 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13206 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13207 | final long identity = Binder.clearCallingIdentity(); |
| 13208 | try { |
| 13209 | if (enableSatellite) { |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13210 | String caller = "PIM:requestSatelliteEnabled"; |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13211 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13212 | @Override |
| 13213 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13214 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13215 | + ", resultData=" + resultData); |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13216 | mSatelliteController.decrementResultReceiverCount(caller); |
| 13217 | |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13218 | boolean isAllowed = false; |
| 13219 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13220 | callback::accept); |
| 13221 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13222 | if (resultData != null |
| 13223 | && resultData.containsKey( |
| 13224 | KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13225 | isAllowed = resultData.getBoolean( |
| 13226 | KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13227 | } else { |
| 13228 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13229 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13230 | } else { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13231 | result.accept(resultCode); |
| 13232 | return; |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13233 | } |
Sangyun Yun | 8bb6645 | 2024-11-25 15:46:10 +0000 | [diff] [blame] | 13234 | List<Integer> disallowedReasons = |
| 13235 | mSatelliteAccessController.getSatelliteDisallowedReasons(); |
| 13236 | if (disallowedReasons.stream().anyMatch(r -> |
| 13237 | (r == SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP |
| 13238 | || r == SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED |
| 13239 | || r == SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED))) { |
| 13240 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13241 | return; |
| 13242 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13243 | if (isAllowed) { |
Thomas Nguyen | dd8e083 | 2024-11-01 00:18:58 +0000 | [diff] [blame] | 13244 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13245 | @Override |
| 13246 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13247 | Log.d(LOG_TAG, "updateSystemSelectionChannels resultCode=" |
| 13248 | + resultCode); |
| 13249 | mSatelliteController.requestSatelliteEnabled( |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 13250 | enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | dd8e083 | 2024-11-01 00:18:58 +0000 | [diff] [blame] | 13251 | } |
| 13252 | }; |
| 13253 | mSatelliteAccessController.updateSystemSelectionChannels( |
| 13254 | resultReceiver); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13255 | } else { |
| 13256 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13257 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13258 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13259 | }; |
| 13260 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
| 13261 | resultReceiver, true); |
youngtaecha | 3a9c8a6 | 2024-11-01 20:46:08 +0000 | [diff] [blame] | 13262 | mSatelliteController.incrementResultReceiverCount(caller); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13263 | } else { |
| 13264 | // No need to check if satellite is allowed at current location when disabling |
| 13265 | // satellite |
| 13266 | mSatelliteController.requestSatelliteEnabled( |
| 13267 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13268 | } |
| 13269 | } finally { |
| 13270 | Binder.restoreCallingIdentity(identity); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13271 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13272 | } |
| 13273 | |
| 13274 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13275 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13276 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13277 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13278 | * 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] | 13279 | * |
| 13280 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13281 | */ |
| 13282 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13283 | public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13284 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13285 | final long identity = Binder.clearCallingIdentity(); |
| 13286 | try { |
| 13287 | mSatelliteController.requestIsSatelliteEnabled(result); |
| 13288 | } finally { |
| 13289 | Binder.restoreCallingIdentity(identity); |
| 13290 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13291 | } |
| 13292 | |
| 13293 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13294 | * Request to get whether the satellite service demo mode is enabled. |
| 13295 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13296 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13297 | * if the request is successful or an error code if the request failed. |
| 13298 | * |
| 13299 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13300 | */ |
| 13301 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13302 | public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13303 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13304 | final long identity = Binder.clearCallingIdentity(); |
| 13305 | try { |
| 13306 | mSatelliteController.requestIsDemoModeEnabled(result); |
| 13307 | } finally { |
| 13308 | Binder.restoreCallingIdentity(identity); |
| 13309 | } |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13310 | } |
| 13311 | |
| 13312 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13313 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13314 | * |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13315 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13316 | * enabled if the request is successful or an error code if the request failed. |
| 13317 | * |
| 13318 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13319 | */ |
| 13320 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13321 | public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) { |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13322 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13323 | final long identity = Binder.clearCallingIdentity(); |
| 13324 | try { |
| 13325 | mSatelliteController.requestIsEmergencyModeEnabled(result); |
| 13326 | } finally { |
| 13327 | Binder.restoreCallingIdentity(identity); |
| 13328 | } |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13329 | } |
| 13330 | |
| 13331 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13332 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13333 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13334 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13335 | * 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] | 13336 | */ |
| 13337 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13338 | public void requestIsSatelliteSupported(@NonNull ResultReceiver result) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13339 | final long identity = Binder.clearCallingIdentity(); |
| 13340 | try { |
| 13341 | mSatelliteController.requestIsSatelliteSupported(result); |
| 13342 | } finally { |
| 13343 | Binder.restoreCallingIdentity(identity); |
| 13344 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13345 | } |
| 13346 | |
| 13347 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13348 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13349 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13350 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13351 | * 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] | 13352 | * |
| 13353 | * @throws SecurityException if the caller doesn't have required permission. |
| 13354 | */ |
| 13355 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13356 | public void requestSatelliteCapabilities(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13357 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13358 | final long identity = Binder.clearCallingIdentity(); |
| 13359 | try { |
| 13360 | mSatelliteController.requestSatelliteCapabilities(result); |
| 13361 | } finally { |
| 13362 | Binder.restoreCallingIdentity(identity); |
| 13363 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13364 | } |
| 13365 | |
| 13366 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13367 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13368 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13369 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13370 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13371 | * @param resultCallback The callback to get the result of the request. |
| 13372 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13373 | * |
| 13374 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13375 | */ |
| 13376 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13377 | public void startSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13378 | @NonNull IIntegerConsumer resultCallback, |
| 13379 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13380 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13381 | final long identity = Binder.clearCallingIdentity(); |
| 13382 | try { |
| 13383 | mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback); |
| 13384 | } finally { |
| 13385 | Binder.restoreCallingIdentity(identity); |
| 13386 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13387 | } |
| 13388 | |
| 13389 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13390 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13391 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13392 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13393 | * @param resultCallback The callback to get the result of the request. |
| 13394 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13395 | * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13396 | * |
| 13397 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13398 | */ |
| 13399 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13400 | public void stopSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13401 | @NonNull IIntegerConsumer resultCallback, |
| 13402 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13403 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13404 | final long identity = Binder.clearCallingIdentity(); |
| 13405 | try { |
| 13406 | mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback); |
| 13407 | } finally { |
| 13408 | Binder.restoreCallingIdentity(identity); |
| 13409 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13410 | } |
| 13411 | |
| 13412 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13413 | * Register the subscription with a satellite provider. |
| 13414 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13415 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13416 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13417 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13418 | * @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] | 13419 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13420 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13421 | * @return The signal transport used by the caller to cancel the provision request, |
| 13422 | * or {@code null} if the request failed. |
| 13423 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13424 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13425 | */ |
| 13426 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13427 | @Nullable public ICancellationSignal provisionSatelliteService( |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13428 | @NonNull String token, @NonNull byte[] provisionData, |
| 13429 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13430 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13431 | final long identity = Binder.clearCallingIdentity(); |
| 13432 | try { |
| 13433 | return mSatelliteController.provisionSatelliteService(token, provisionData, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13434 | callback); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13435 | } finally { |
| 13436 | Binder.restoreCallingIdentity(identity); |
| 13437 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13438 | } |
| 13439 | |
| 13440 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13441 | * Unregister the device/subscription with the satellite provider. |
| 13442 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13443 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13444 | * should report as deprovisioned. |
| 13445 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13446 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13447 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13448 | * |
| 13449 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13450 | */ |
| 13451 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13452 | public void deprovisionSatelliteService( |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13453 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13454 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13455 | final long identity = Binder.clearCallingIdentity(); |
| 13456 | try { |
| 13457 | mSatelliteController.deprovisionSatelliteService(token, callback); |
| 13458 | } finally { |
| 13459 | Binder.restoreCallingIdentity(identity); |
| 13460 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13461 | } |
| 13462 | |
| 13463 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13464 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13465 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13466 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13467 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13468 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13469 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13470 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13471 | */ |
| 13472 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13473 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13474 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13475 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13476 | final long identity = Binder.clearCallingIdentity(); |
| 13477 | try { |
| 13478 | return mSatelliteController.registerForSatelliteProvisionStateChanged(callback); |
| 13479 | } finally { |
| 13480 | Binder.restoreCallingIdentity(identity); |
| 13481 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13482 | } |
| 13483 | |
| 13484 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13485 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13486 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13487 | * |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13488 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13489 | * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13490 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13491 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13492 | */ |
| 13493 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13494 | public void unregisterForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13495 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13496 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13497 | final long identity = Binder.clearCallingIdentity(); |
| 13498 | try { |
| 13499 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback); |
| 13500 | } finally { |
| 13501 | Binder.restoreCallingIdentity(identity); |
| 13502 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13503 | } |
| 13504 | |
| 13505 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13506 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13507 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13508 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13509 | * satellite provider if the request is successful or an error code if the |
| 13510 | * request failed. |
| 13511 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13512 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13513 | */ |
| 13514 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13515 | public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13516 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13517 | final long identity = Binder.clearCallingIdentity(); |
| 13518 | try { |
| 13519 | mSatelliteController.requestIsSatelliteProvisioned(result); |
| 13520 | } finally { |
| 13521 | Binder.restoreCallingIdentity(identity); |
| 13522 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13523 | } |
| 13524 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13525 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13526 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13527 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13528 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13529 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13530 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13531 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13532 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13533 | */ |
| 13534 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13535 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged( |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13536 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13537 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13538 | final long identity = Binder.clearCallingIdentity(); |
| 13539 | try { |
| 13540 | return mSatelliteController.registerForSatelliteModemStateChanged(callback); |
| 13541 | } finally { |
| 13542 | Binder.restoreCallingIdentity(identity); |
| 13543 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13544 | } |
| 13545 | |
| 13546 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13547 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13548 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13549 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13550 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13551 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13552 | * |
| 13553 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13554 | */ |
| 13555 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13556 | public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13557 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13558 | final long identity = Binder.clearCallingIdentity(); |
| 13559 | try { |
| 13560 | mSatelliteController.unregisterForModemStateChanged(callback); |
| 13561 | } finally { |
| 13562 | Binder.restoreCallingIdentity(identity); |
| 13563 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13564 | } |
| 13565 | |
| 13566 | /** |
| 13567 | * Register to receive incoming datagrams over satellite. |
| 13568 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13569 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13570 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13571 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13572 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13573 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13574 | */ |
| 13575 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13576 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram( |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13577 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13578 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13579 | final long identity = Binder.clearCallingIdentity(); |
| 13580 | try { |
| 13581 | return mSatelliteController.registerForIncomingDatagram(callback); |
| 13582 | } finally { |
| 13583 | Binder.restoreCallingIdentity(identity); |
| 13584 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13585 | } |
| 13586 | |
| 13587 | /** |
| 13588 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13589 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13590 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13591 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13592 | * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13593 | * |
| 13594 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13595 | */ |
| 13596 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13597 | public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13598 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13599 | final long identity = Binder.clearCallingIdentity(); |
| 13600 | try { |
| 13601 | mSatelliteController.unregisterForIncomingDatagram(callback); |
| 13602 | } finally { |
| 13603 | Binder.restoreCallingIdentity(identity); |
| 13604 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13605 | } |
| 13606 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13607 | /** |
| 13608 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13609 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13610 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13611 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13612 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13613 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13614 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13615 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13616 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13617 | */ |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13618 | public void pollPendingDatagrams(IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13619 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13620 | final long identity = Binder.clearCallingIdentity(); |
| 13621 | try { |
| 13622 | mSatelliteController.pollPendingDatagrams(callback); |
| 13623 | } finally { |
| 13624 | Binder.restoreCallingIdentity(identity); |
| 13625 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13626 | } |
| 13627 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13628 | /** |
| 13629 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13630 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13631 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13632 | * input to this method. Datagram received here will be passed down to modem without any |
| 13633 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13634 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13635 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13636 | * SOS_SMS or LOCATION_SHARING. |
| 13637 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13638 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13639 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13640 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13641 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13642 | * |
| 13643 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13644 | */ |
| 13645 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13646 | public void sendDatagram(@SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13647 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13648 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13649 | enforceSatelliteCommunicationPermission("sendDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13650 | final long identity = Binder.clearCallingIdentity(); |
| 13651 | try { |
| 13652 | mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI, |
| 13653 | callback); |
| 13654 | } finally { |
| 13655 | Binder.restoreCallingIdentity(identity); |
| 13656 | } |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13657 | } |
| 13658 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13659 | /** |
Duke Lee | 8852e51 | 2024-10-06 12:55:43 +0900 | [diff] [blame] | 13660 | * Returns integer array of disallowed reasons of satellite. |
| 13661 | * |
| 13662 | * @return Integer array of disallowed reasons of satellite. |
| 13663 | * |
| 13664 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13665 | */ |
| 13666 | @NonNull public int[] getSatelliteDisallowedReasons() { |
| 13667 | enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons"); |
| 13668 | final long identity = Binder.clearCallingIdentity(); |
| 13669 | try { |
| 13670 | return mSatelliteAccessController.getSatelliteDisallowedReasons() |
| 13671 | .stream().mapToInt(Integer::intValue).toArray(); |
| 13672 | } finally { |
| 13673 | Binder.restoreCallingIdentity(identity); |
| 13674 | } |
| 13675 | } |
| 13676 | |
| 13677 | /** |
| 13678 | * Registers for disallowed reasons change event from satellite service. |
| 13679 | * |
| 13680 | * @param callback The callback to handle disallowed reasons changed event. |
| 13681 | * |
| 13682 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13683 | */ |
| 13684 | @Override |
| 13685 | public void registerForSatelliteDisallowedReasonsChanged( |
| 13686 | @NonNull ISatelliteDisallowedReasonsCallback callback) { |
| 13687 | enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged"); |
| 13688 | final long identity = Binder.clearCallingIdentity(); |
| 13689 | try { |
| 13690 | mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback); |
| 13691 | } finally { |
| 13692 | Binder.restoreCallingIdentity(identity); |
| 13693 | } |
| 13694 | } |
| 13695 | |
| 13696 | /** |
| 13697 | * Unregisters for disallowed reasons change event from satellite service. |
| 13698 | * If callback was not registered before, the request will be ignored. |
| 13699 | * |
| 13700 | * @param callback The callback to handle disallowed reasons changed event. |
| 13701 | * {@link #registerForSatelliteDisallowedReasonsChanged( |
| 13702 | * ISatelliteDisallowedReasonsCallback)}. |
| 13703 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13704 | */ |
| 13705 | @Override |
| 13706 | public void unregisterForSatelliteDisallowedReasonsChanged( |
| 13707 | @NonNull ISatelliteDisallowedReasonsCallback callback) { |
| 13708 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged"); |
| 13709 | final long identity = Binder.clearCallingIdentity(); |
| 13710 | try { |
| 13711 | mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback); |
| 13712 | } finally { |
| 13713 | Binder.restoreCallingIdentity(identity); |
| 13714 | } |
| 13715 | } |
| 13716 | |
| 13717 | /** |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13718 | * Request to get whether satellite communication is allowed for the current location. |
| 13719 | * |
| 13720 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13721 | * allowed for the current location for. |
| 13722 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13723 | * for the current location if the request is successful or an error code |
| 13724 | * if the request failed. |
| 13725 | * |
| 13726 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13727 | */ |
| 13728 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13729 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13730 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13731 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13732 | final long identity = Binder.clearCallingIdentity(); |
| 13733 | try { |
| 13734 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, |
| 13735 | false); |
| 13736 | } finally { |
| 13737 | Binder.restoreCallingIdentity(identity); |
| 13738 | } |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13739 | } |
| 13740 | |
| 13741 | /** |
youngtaecha | edc8a1c | 2024-10-15 09:07:25 +0000 | [diff] [blame] | 13742 | * Request to get satellite access configuration for the current location. |
| 13743 | * |
| 13744 | * @param result The result receiver that returns the satellite access configuration |
| 13745 | * for the current location if the request is successful or an error code |
| 13746 | * if the request failed. |
| 13747 | * |
| 13748 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13749 | */ |
| 13750 | @Override |
| 13751 | public void requestSatelliteAccessConfigurationForCurrentLocation( |
| 13752 | @NonNull ResultReceiver result) { |
| 13753 | enforceSatelliteCommunicationPermission( |
| 13754 | "requestSatelliteAccessConfigurationForCurrentLocation"); |
| 13755 | final long identity = Binder.clearCallingIdentity(); |
| 13756 | try { |
| 13757 | mSatelliteAccessController |
| 13758 | .requestSatelliteAccessConfigurationForCurrentLocation(result); |
| 13759 | } finally { |
| 13760 | Binder.restoreCallingIdentity(identity); |
| 13761 | } |
| 13762 | } |
| 13763 | |
| 13764 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13765 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13766 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13767 | * @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] | 13768 | * be visible if the request is successful or an error code if the request failed. |
| 13769 | * |
| 13770 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13771 | */ |
| 13772 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13773 | public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13774 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13775 | final long identity = Binder.clearCallingIdentity(); |
| 13776 | try { |
| 13777 | mSatelliteController.requestTimeForNextSatelliteVisibility(result); |
| 13778 | } finally { |
| 13779 | Binder.restoreCallingIdentity(identity); |
| 13780 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13781 | } |
| 13782 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13783 | /** |
Adrian | 8e30ad0 | 2024-11-21 17:22:29 +0000 | [diff] [blame] | 13784 | * Request to get the name to display for Satellite subscription. |
| 13785 | * |
| 13786 | * @param result The result receiver that returns the display name to use for satellite feature |
| 13787 | * in the UI for current satellite subscription if the request is successful, |
| 13788 | * or an error code if the request failed. |
| 13789 | * |
| 13790 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13791 | */ |
| 13792 | @Override |
| 13793 | public void requestSatelliteDisplayName(@NonNull ResultReceiver result) { |
| 13794 | enforceSatelliteCommunicationPermission("requestSatelliteDisplayName"); |
| 13795 | final long identity = Binder.clearCallingIdentity(); |
| 13796 | try { |
| 13797 | mSatelliteController.requestSatelliteDisplayName(result); |
| 13798 | } finally { |
| 13799 | Binder.restoreCallingIdentity(identity); |
| 13800 | } |
| 13801 | } |
| 13802 | |
| 13803 | /** |
Daniel Banta | 99cc753 | 2024-11-15 02:31:08 +0000 | [diff] [blame] | 13804 | * Request to get the currently selected satellite subscription id. |
| 13805 | * |
| 13806 | * @param result The result receiver that returns the currently selected satellite subscription |
| 13807 | * id if the request is successful or an error code if the request failed. |
| 13808 | * |
| 13809 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13810 | */ |
| 13811 | @Override |
| 13812 | public void requestSelectedNbIotSatelliteSubscriptionId(@NonNull ResultReceiver result) { |
| 13813 | enforceSatelliteCommunicationPermission("requestSelectedNbIotSatelliteSubscriptionId"); |
| 13814 | final long identity = Binder.clearCallingIdentity(); |
| 13815 | try { |
| 13816 | mSatelliteController.requestSelectedNbIotSatelliteSubscriptionId(result); |
| 13817 | } finally { |
| 13818 | Binder.restoreCallingIdentity(identity); |
| 13819 | } |
| 13820 | } |
| 13821 | |
| 13822 | /** |
Daniel Banta | 9332024 | 2024-11-21 00:34:41 +0000 | [diff] [blame] | 13823 | * Registers for selected satellite subscription changed event from the satellite service. |
| 13824 | * |
| 13825 | * @param callback The callback to handle the satellite subscription changed event. |
| 13826 | * |
| 13827 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13828 | * |
| 13829 | * @throws SecurityException if the caller doesn't have required permission. |
| 13830 | */ |
| 13831 | @Override |
| 13832 | @SatelliteManager.SatelliteResult |
| 13833 | public int registerForSelectedNbIotSatelliteSubscriptionChanged( |
| 13834 | @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) { |
| 13835 | enforceSatelliteCommunicationPermission( |
| 13836 | "registerForSelectedNbIotSatelliteSubscriptionChanged"); |
| 13837 | final long identity = Binder.clearCallingIdentity(); |
| 13838 | try { |
| 13839 | return mSatelliteController.registerForSelectedNbIotSatelliteSubscriptionChanged( |
| 13840 | callback); |
| 13841 | } finally { |
| 13842 | Binder.restoreCallingIdentity(identity); |
| 13843 | } |
| 13844 | } |
| 13845 | |
| 13846 | /** |
| 13847 | * Unregisters for selected satellite subscription changed event from the satellite service. |
| 13848 | * If callback was not registered before, the request will be ignored. |
| 13849 | * |
| 13850 | * @param callback The callback that was passed to {@link |
| 13851 | * #registerForSelectedNbIotSatelliteSubscriptionChanged( |
| 13852 | * ISelectedNbIotSatelliteSubscriptionCallback)}. |
| 13853 | * |
| 13854 | * @throws SecurityException if the caller doesn't have required permission. |
| 13855 | */ |
| 13856 | @Override |
| 13857 | public void unregisterForSelectedNbIotSatelliteSubscriptionChanged( |
| 13858 | @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) { |
| 13859 | enforceSatelliteCommunicationPermission( |
| 13860 | "unregisterForSelectedNbIotSatelliteSubscriptionChanged"); |
| 13861 | final long identity = Binder.clearCallingIdentity(); |
| 13862 | try { |
| 13863 | mSatelliteController.unregisterForSelectedNbIotSatelliteSubscriptionChanged( |
| 13864 | callback); |
| 13865 | } finally { |
| 13866 | Binder.restoreCallingIdentity(identity); |
| 13867 | } |
| 13868 | } |
| 13869 | |
| 13870 | /** |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13871 | * Inform whether the device is aligned with the satellite in both real and demo mode. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13872 | * |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13873 | * @param isAligned {@code true} Device is aligned with the satellite. |
| 13874 | * {@code false} Device fails to align with the satellite. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13875 | * |
| 13876 | * @throws SecurityException if the caller doesn't have required permission. |
| 13877 | */ |
| 13878 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13879 | |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13880 | public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13881 | enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite"); |
| 13882 | final long identity = Binder.clearCallingIdentity(); |
| 13883 | try { |
| 13884 | mSatelliteController.setDeviceAlignedWithSatellite(isAligned); |
| 13885 | } finally { |
| 13886 | Binder.restoreCallingIdentity(identity); |
| 13887 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13888 | } |
| 13889 | |
| 13890 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13891 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13892 | * by modem. |
| 13893 | * |
| 13894 | * @param subId The subId of the subscription to request for. |
| 13895 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13896 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13897 | * operation. |
| 13898 | * |
| 13899 | * @throws SecurityException if the caller doesn't have required permission. |
| 13900 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13901 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13902 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13903 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13904 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13905 | final long identity = Binder.clearCallingIdentity(); |
| 13906 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13907 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13908 | } finally { |
| 13909 | Binder.restoreCallingIdentity(identity); |
| 13910 | } |
| 13911 | } |
| 13912 | |
| 13913 | /** |
| 13914 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13915 | * by modem. |
| 13916 | * |
| 13917 | * @param subId The subId of the subscription to request for. |
| 13918 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13919 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13920 | * operation. |
| 13921 | * |
| 13922 | * @throws SecurityException if the caller doesn't have required permission. |
| 13923 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13924 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13925 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13926 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13927 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13928 | final long identity = Binder.clearCallingIdentity(); |
| 13929 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13930 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13931 | } finally { |
| 13932 | Binder.restoreCallingIdentity(identity); |
| 13933 | } |
| 13934 | } |
| 13935 | |
| 13936 | /** |
| 13937 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13938 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13939 | * |
| 13940 | * @param subId The subId of the subscription to request for. |
| 13941 | * |
| 13942 | * @return Integer array of reasons for disallowing satellite communication. |
| 13943 | * |
| 13944 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13945 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13946 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13947 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13948 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13949 | final long identity = Binder.clearCallingIdentity(); |
| 13950 | try { |
| 13951 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13952 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13953 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13954 | } finally { |
| 13955 | Binder.restoreCallingIdentity(identity); |
| 13956 | } |
| 13957 | } |
| 13958 | |
| 13959 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13960 | * Request to get the signal strength of the satellite connection. |
| 13961 | * |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13962 | * @param result Result receiver to get the error code of the request and the current signal |
| 13963 | * strength of the satellite connection. |
| 13964 | * |
| 13965 | * @throws SecurityException if the caller doesn't have required permission. |
| 13966 | */ |
| 13967 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13968 | public void requestNtnSignalStrength(@NonNull ResultReceiver result) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13969 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13970 | final long identity = Binder.clearCallingIdentity(); |
| 13971 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13972 | mSatelliteController.requestNtnSignalStrength(result); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13973 | } finally { |
| 13974 | Binder.restoreCallingIdentity(identity); |
| 13975 | } |
| 13976 | } |
| 13977 | |
| 13978 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13979 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13980 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13981 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13982 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13983 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13984 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13985 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13986 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13987 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13988 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13989 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13990 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13991 | */ |
| 13992 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13993 | public void registerForNtnSignalStrengthChanged( |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13994 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13995 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13996 | final long identity = Binder.clearCallingIdentity(); |
| 13997 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13998 | mSatelliteController.registerForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13999 | } finally { |
| 14000 | Binder.restoreCallingIdentity(identity); |
| 14001 | } |
| 14002 | } |
| 14003 | |
| 14004 | /** |
| 14005 | * Unregisters for NTN signal strength changed from satellite modem. |
| 14006 | * If callback was not registered before, the request will be ignored. |
| 14007 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14008 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14009 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14010 | * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)} |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14011 | * |
| 14012 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14013 | */ |
| 14014 | @Override |
| 14015 | public void unregisterForNtnSignalStrengthChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14016 | @NonNull INtnSignalStrengthCallback callback) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14017 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 14018 | final long identity = Binder.clearCallingIdentity(); |
| 14019 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14020 | mSatelliteController.unregisterForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 14021 | } finally { |
| 14022 | Binder.restoreCallingIdentity(identity); |
| 14023 | } |
| 14024 | } |
| 14025 | |
| 14026 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14027 | * Registers for satellite capabilities change event from the satellite service. |
| 14028 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14029 | * @param callback The callback to handle the satellite capabilities changed event. |
| 14030 | * |
| 14031 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14032 | * |
| 14033 | * @throws SecurityException if the caller doesn't have required permission. |
| 14034 | */ |
| 14035 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 14036 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14037 | @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 14038 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14039 | final long identity = Binder.clearCallingIdentity(); |
| 14040 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14041 | return mSatelliteController.registerForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14042 | } finally { |
| 14043 | Binder.restoreCallingIdentity(identity); |
| 14044 | } |
| 14045 | } |
| 14046 | |
| 14047 | /** |
| 14048 | * Unregisters for satellite capabilities change event from the satellite service. |
| 14049 | * If callback was not registered before, the request will be ignored. |
| 14050 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14051 | * @param callback The callback that was passed to. |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14052 | * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14053 | * |
| 14054 | * @throws SecurityException if the caller doesn't have required permission. |
| 14055 | */ |
| 14056 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14057 | public void unregisterForCapabilitiesChanged( |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 14058 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 14059 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14060 | final long identity = Binder.clearCallingIdentity(); |
| 14061 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14062 | mSatelliteController.unregisterForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 14063 | } finally { |
| 14064 | Binder.restoreCallingIdentity(identity); |
| 14065 | } |
| 14066 | } |
| 14067 | |
| 14068 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14069 | * Registers for the satellite supported state changed. |
| 14070 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14071 | * @param callback The callback to handle the satellite supported state changed event. |
| 14072 | * |
| 14073 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14074 | * |
| 14075 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14076 | */ |
| 14077 | @Override |
| 14078 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14079 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14080 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14081 | final long identity = Binder.clearCallingIdentity(); |
| 14082 | try { |
| 14083 | return mSatelliteController.registerForSatelliteSupportedStateChanged(callback); |
| 14084 | } finally { |
| 14085 | Binder.restoreCallingIdentity(identity); |
| 14086 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14087 | } |
| 14088 | |
| 14089 | /** |
| 14090 | * Unregisters for the satellite supported state changed. |
| 14091 | * If callback was not registered before, the request will be ignored. |
| 14092 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14093 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14094 | * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14095 | * |
| 14096 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14097 | */ |
| 14098 | @Override |
| 14099 | public void unregisterForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 14100 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14101 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14102 | final long identity = Binder.clearCallingIdentity(); |
| 14103 | try { |
| 14104 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback); |
| 14105 | } finally { |
| 14106 | Binder.restoreCallingIdentity(identity); |
| 14107 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 14108 | } |
| 14109 | |
| 14110 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14111 | * This API can be used by only CTS to update satellite vendor service package name. |
| 14112 | * |
| 14113 | * @param servicePackageName The package name of the satellite vendor service. |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 14114 | * @param provisioned Whether satellite should be provisioned or not. |
| 14115 | * |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14116 | * @return {@code true} if the satellite vendor service is set successfully, |
| 14117 | * {@code false} otherwise. |
| 14118 | */ |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 14119 | public boolean setSatelliteServicePackageName(String servicePackageName, |
| 14120 | String provisioned) { |
| 14121 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName |
| 14122 | + ", provisioned=" + provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14123 | TelephonyPermissions.enforceShellOnly( |
| 14124 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 14125 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14126 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14127 | "setSatelliteServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14128 | final long identity = Binder.clearCallingIdentity(); |
| 14129 | try { |
| 14130 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName, |
| 14131 | provisioned); |
| 14132 | } finally { |
| 14133 | Binder.restoreCallingIdentity(identity); |
| 14134 | } |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 14135 | } |
| 14136 | |
| 14137 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 14138 | * This API can be used by only CTS to update satellite gateway service package name. |
| 14139 | * |
| 14140 | * @param servicePackageName The package name of the satellite gateway service. |
| 14141 | * @return {@code true} if the satellite gateway service is set successfully, |
| 14142 | * {@code false} otherwise. |
| 14143 | */ |
| 14144 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 14145 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 14146 | TelephonyPermissions.enforceShellOnly( |
| 14147 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 14148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14149 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14150 | "setSatelliteGatewayServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14151 | final long identity = Binder.clearCallingIdentity(); |
| 14152 | try { |
| 14153 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 14154 | } finally { |
| 14155 | Binder.restoreCallingIdentity(identity); |
| 14156 | } |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 14157 | } |
| 14158 | |
| 14159 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 14160 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 14161 | * |
| 14162 | * @param packageName The package name of the satellite pointing UI app. |
| 14163 | * @param className The class name of the satellite pointing UI app. |
| 14164 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 14165 | * {@code false} otherwise. |
| 14166 | */ |
| 14167 | public boolean setSatellitePointingUiClassName( |
| 14168 | @Nullable String packageName, @Nullable String className) { |
| 14169 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 14170 | + ", className=" + className); |
| 14171 | TelephonyPermissions.enforceShellOnly( |
| 14172 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 14173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14174 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14175 | "setSatellitePointingUiClassName"); |
| 14176 | final long identity = Binder.clearCallingIdentity(); |
| 14177 | try { |
| 14178 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 14179 | } finally { |
| 14180 | Binder.restoreCallingIdentity(identity); |
| 14181 | } |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 14182 | } |
| 14183 | |
| 14184 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14185 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 14186 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 14187 | * listening mode. |
| 14188 | * |
| 14189 | * @param timeoutMillis The timeout duration in millisecond. |
| 14190 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14191 | */ |
| 14192 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 14193 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 14194 | TelephonyPermissions.enforceShellOnly( |
| 14195 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 14196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14197 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14198 | "setSatelliteListeningTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14199 | final long identity = Binder.clearCallingIdentity(); |
| 14200 | try { |
| 14201 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 14202 | } finally { |
| 14203 | Binder.restoreCallingIdentity(identity); |
| 14204 | } |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14205 | } |
| 14206 | |
| 14207 | /** |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14208 | * This API can be used by only CTS to control ingoring cellular service state event. |
| 14209 | * |
| 14210 | * @param enabled Whether to enable boolean config. |
| 14211 | * @return {@code true} if the value is set successfully, {@code false} otherwise. |
| 14212 | */ |
| 14213 | public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14214 | Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14215 | TelephonyPermissions.enforceShellOnly( |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14216 | Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState"); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14217 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14218 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14219 | "setSatelliteIgnoreCellularServiceState"); |
| 14220 | final long identity = Binder.clearCallingIdentity(); |
| 14221 | try { |
| 14222 | return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled); |
| 14223 | } finally { |
| 14224 | Binder.restoreCallingIdentity(identity); |
| 14225 | } |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14226 | } |
| 14227 | |
| 14228 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14229 | * This API can be used by only CTS to override the timeout durations used by the |
| 14230 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14231 | * |
| 14232 | * @param timeoutMillis The timeout duration in millisecond. |
| 14233 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14234 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14235 | public boolean setDatagramControllerTimeoutDuration( |
| 14236 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14237 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14238 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14239 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14240 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14242 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14243 | "setDatagramControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14244 | final long identity = Binder.clearCallingIdentity(); |
| 14245 | try { |
| 14246 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 14247 | reset, timeoutType, timeoutMillis); |
| 14248 | } finally { |
| 14249 | Binder.restoreCallingIdentity(identity); |
| 14250 | } |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14251 | } |
| 14252 | |
| 14253 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14254 | * This API can be used by only CTS to override the boolean configs used by the |
| 14255 | * DatagramController module. |
| 14256 | * |
| 14257 | * @param enable Whether to enable or disable boolean config. |
| 14258 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 14259 | */ |
| 14260 | public boolean setDatagramControllerBooleanConfig( |
| 14261 | boolean reset, int booleanType, boolean enable) { |
| 14262 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 14263 | + ", reset=" + reset + ", enable=" + enable); |
| 14264 | TelephonyPermissions.enforceShellOnly( |
| 14265 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 14266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14267 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14268 | "ssetDatagramControllerBooleanConfig"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14269 | final long identity = Binder.clearCallingIdentity(); |
| 14270 | try { |
| 14271 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, |
| 14272 | enable); |
| 14273 | } finally { |
| 14274 | Binder.restoreCallingIdentity(identity); |
| 14275 | } |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14276 | } |
| 14277 | |
| 14278 | |
| 14279 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14280 | * This API can be used by only CTS to override the timeout durations used by the |
| 14281 | * SatelliteController module. |
| 14282 | * |
| 14283 | * @param timeoutMillis The timeout duration in millisecond. |
| 14284 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14285 | */ |
| 14286 | public boolean setSatelliteControllerTimeoutDuration( |
| 14287 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14288 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14289 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 14290 | TelephonyPermissions.enforceShellOnly( |
| 14291 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 14292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14293 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14294 | "setSatelliteControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14295 | final long identity = Binder.clearCallingIdentity(); |
| 14296 | try { |
| 14297 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 14298 | reset, timeoutType, timeoutMillis); |
| 14299 | } finally { |
| 14300 | Binder.restoreCallingIdentity(identity); |
| 14301 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14302 | } |
| 14303 | |
| 14304 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14305 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 14306 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 14307 | * |
| 14308 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 14309 | * of the following values to enable the override: |
| 14310 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 14311 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 14312 | * To disable the override, use -1 for handoverType. |
| 14313 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 14314 | * delaySeconds after the emergency call starts. |
| 14315 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 14316 | */ |
| 14317 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 14318 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 14319 | TelephonyPermissions.enforceShellOnly( |
| 14320 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 14321 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14322 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14323 | "setEmergencyCallToSatelliteHandoverType"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14324 | final long identity = Binder.clearCallingIdentity(); |
| 14325 | try { |
| 14326 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 14327 | handoverType, delaySeconds); |
| 14328 | } finally { |
| 14329 | Binder.restoreCallingIdentity(identity); |
| 14330 | } |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14331 | } |
| 14332 | |
| 14333 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14334 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 14335 | * |
| 14336 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 14337 | * otherwise. |
| 14338 | * @param isProvisioned The overriding provision status. |
| 14339 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 14340 | */ |
| 14341 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 14342 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 14343 | + ", isProvisioned=" + isProvisioned); |
| 14344 | TelephonyPermissions.enforceShellOnly( |
| 14345 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 14346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14347 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14348 | "setOemEnabledSatelliteProvisionStatus"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14349 | final long identity = Binder.clearCallingIdentity(); |
| 14350 | try { |
| 14351 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 14352 | } finally { |
| 14353 | Binder.restoreCallingIdentity(identity); |
| 14354 | } |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14355 | } |
| 14356 | |
| 14357 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14358 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 14359 | * |
| 14360 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 14361 | */ |
| 14362 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 14363 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 14364 | long locationCountryCodeTimestampNanos) { |
| 14365 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 14366 | + String.join(", ", currentNetworkCountryCodes) |
| 14367 | + ", locationCountryCode=" + locationCountryCode |
| 14368 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 14369 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 14370 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14371 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes"); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14373 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes"); |
| 14374 | final long identity = Binder.clearCallingIdentity(); |
| 14375 | try { |
| 14376 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), |
| 14377 | mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes, |
| 14378 | cachedNetworkCountryCodes, locationCountryCode, |
| 14379 | locationCountryCodeTimestampNanos); |
| 14380 | } finally { |
| 14381 | Binder.restoreCallingIdentity(identity); |
| 14382 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14383 | } |
| 14384 | |
| 14385 | /** |
| 14386 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 14387 | * access controller. |
| 14388 | * |
| 14389 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 14390 | * otherwise. |
| 14391 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 14392 | */ |
| 14393 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 14394 | String s2CellFile, long locationFreshDurationNanos, |
Hakjun Choi | 364b6ff | 2024-11-20 07:38:44 +0000 | [diff] [blame] | 14395 | List<String> satelliteCountryCodes, String satelliteAccessConfigurationFile) { |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14396 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 14397 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 14398 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 14399 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
Hakjun Choi | 364b6ff | 2024-11-20 07:38:44 +0000 | [diff] [blame] | 14400 | ? String.join(", ", satelliteCountryCodes) : null) |
| 14401 | + ", satelliteAccessConfigurationFile=" + satelliteAccessConfigurationFile); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14402 | TelephonyPermissions.enforceShellOnly( |
| 14403 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 14404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14405 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14406 | "setSatelliteAccessControlOverlayConfigs"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14407 | final long identity = Binder.clearCallingIdentity(); |
| 14408 | try { |
| 14409 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, |
Hakjun Choi | 364b6ff | 2024-11-20 07:38:44 +0000 | [diff] [blame] | 14410 | isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes, |
| 14411 | satelliteAccessConfigurationFile); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14412 | } finally { |
| 14413 | Binder.restoreCallingIdentity(identity); |
| 14414 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14415 | } |
| 14416 | |
| 14417 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14418 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14419 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 14420 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 14421 | * |
| 14422 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 14423 | * satellite modem or not. |
| 14424 | * |
| 14425 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 14426 | */ |
| 14427 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 14428 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14429 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14430 | + "disabled"); |
| 14431 | return false; |
| 14432 | } |
| 14433 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14434 | TelephonyPermissions.enforceShellOnly( |
| 14435 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14437 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14438 | "setShouldSendDatagramToModemInDemoMode"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14439 | final long identity = Binder.clearCallingIdentity(); |
| 14440 | try { |
| 14441 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14442 | shouldSendToModemInDemoMode); |
| 14443 | } finally { |
| 14444 | Binder.restoreCallingIdentity(identity); |
| 14445 | } |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14446 | } |
| 14447 | |
| 14448 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14449 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14450 | * |
| 14451 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14452 | * the allowed state. |
| 14453 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14454 | */ |
| 14455 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14456 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14457 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14458 | + "oemEnabledSatelliteFlag is disabled"); |
| 14459 | return false; |
| 14460 | } |
| 14461 | |
| 14462 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14463 | + "state=" + state); |
| 14464 | TelephonyPermissions.enforceShellOnly( |
| 14465 | Binder.getCallingUid(), |
| 14466 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14467 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14468 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14469 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14470 | final long identity = Binder.clearCallingIdentity(); |
| 14471 | try { |
| 14472 | return mSatelliteAccessController |
| 14473 | .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state); |
| 14474 | } finally { |
| 14475 | Binder.restoreCallingIdentity(identity); |
| 14476 | } |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14477 | } |
| 14478 | |
| 14479 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14480 | * Sets the service defined in ComponentName to be bound. |
| 14481 | * |
| 14482 | * This should only be used for testing. |
| 14483 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14484 | * {@code false} otherwise. |
| 14485 | */ |
| 14486 | @Override |
| 14487 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14488 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14489 | |
| 14490 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14491 | "setDomainSelectionServiceOverride"); |
| 14492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14493 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14494 | |
| 14495 | final long identity = Binder.clearCallingIdentity(); |
| 14496 | try { |
| 14497 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14498 | return DomainSelectionResolver.getInstance() |
| 14499 | .setDomainSelectionServiceOverride(componentName); |
| 14500 | } |
| 14501 | } finally { |
| 14502 | Binder.restoreCallingIdentity(identity); |
| 14503 | } |
| 14504 | return false; |
| 14505 | } |
| 14506 | |
| 14507 | /** |
| 14508 | * Clears the DomainSelectionService override. |
| 14509 | * |
| 14510 | * This should only be used for testing. |
| 14511 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14512 | * {@code false} otherwise. |
| 14513 | */ |
| 14514 | @Override |
| 14515 | public boolean clearDomainSelectionServiceOverride() { |
| 14516 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14517 | |
| 14518 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14519 | "clearDomainSelectionServiceOverride"); |
| 14520 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14521 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14522 | |
| 14523 | final long identity = Binder.clearCallingIdentity(); |
| 14524 | try { |
| 14525 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14526 | return DomainSelectionResolver.getInstance() |
| 14527 | .clearDomainSelectionServiceOverride(); |
| 14528 | } |
| 14529 | } finally { |
| 14530 | Binder.restoreCallingIdentity(identity); |
| 14531 | } |
| 14532 | return false; |
| 14533 | } |
| 14534 | |
| 14535 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14536 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14537 | * |
| 14538 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14539 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14540 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14541 | * |
| 14542 | * @param enable if notifications about disclosure events should be enabled |
| 14543 | * @throws SecurityException if the caller does not have the required privileges |
| 14544 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14545 | */ |
| 14546 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14547 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14548 | enforceModifyPermission(); |
| 14549 | checkForIdentifierDisclosureNotificationSupport(); |
| 14550 | |
| 14551 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14552 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14553 | editor.apply(); |
| 14554 | |
| 14555 | // Each phone instance is responsible for updating its respective modem immediately |
| 14556 | // after we've made a preference change. |
| 14557 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14558 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14559 | } |
| 14560 | } |
| 14561 | |
| 14562 | /** |
| 14563 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14564 | * |
| 14565 | * @throws SecurityException if the caller does not have the required privileges |
| 14566 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14567 | */ |
| 14568 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14569 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14570 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14571 | checkForIdentifierDisclosureNotificationSupport(); |
| 14572 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14573 | } |
| 14574 | |
| 14575 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14576 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14577 | * are in use by the cellular modem. |
| 14578 | * |
| 14579 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14580 | * @throws SecurityException if the caller does not have the required privileges |
| 14581 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14582 | * and integrity algorithms in use |
| 14583 | * @hide |
| 14584 | */ |
| 14585 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14586 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14587 | enforceModifyPermission(); |
| 14588 | checkForNullCipherNotificationSupport(); |
| 14589 | |
| 14590 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14591 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14592 | editor.apply(); |
| 14593 | |
| 14594 | // Each phone instance is responsible for updating its respective modem immediately |
| 14595 | // after a preference change. |
| 14596 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14597 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14598 | } |
| 14599 | } |
| 14600 | |
| 14601 | /** |
| 14602 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14603 | * cellular modem. |
| 14604 | * |
| 14605 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14606 | * @throws SecurityException if the caller does not have the required privileges |
| 14607 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14608 | * and integrity algorithms in use |
| 14609 | * @hide |
| 14610 | */ |
| 14611 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14612 | public boolean isNullCipherNotificationsEnabled() { |
| 14613 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14614 | checkForNullCipherNotificationSupport(); |
| 14615 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14616 | } |
| 14617 | |
| 14618 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14619 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14620 | * |
| 14621 | * <p>This method behaves in one of the following ways: |
| 14622 | * <ul> |
| 14623 | * <li>return true : if the calling package has the appop permission {@link |
| 14624 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14625 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14626 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14627 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14628 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14629 | * </ul> |
| 14630 | */ |
| 14631 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14632 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14633 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14634 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14635 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14636 | return true; |
| 14637 | } |
| 14638 | } |
| 14639 | return false; |
| 14640 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14641 | |
| 14642 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14643 | * @return The subscription manager service instance. |
| 14644 | */ |
| 14645 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14646 | return SubscriptionManagerService.getInstance(); |
| 14647 | } |
| 14648 | |
| 14649 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14650 | * Class binds the consumer[callback] and carrierId. |
| 14651 | */ |
| 14652 | private static class CallerCallbackInfo { |
| 14653 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14654 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14655 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14656 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14657 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14658 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14659 | } |
| 14660 | |
| 14661 | public Consumer<Integer> getConsumer() { |
| 14662 | return mConsumer; |
| 14663 | } |
| 14664 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14665 | public Set<Integer> getCarrierIds() { |
| 14666 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14667 | } |
| 14668 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14669 | |
| 14670 | /* |
| 14671 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14672 | * But the context that is passed in is unused if the phone app is already alive. |
| 14673 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14674 | */ |
| 14675 | @VisibleForTesting |
| 14676 | public void setPackageManager(PackageManager packageManager) { |
| 14677 | mPackageManager = packageManager; |
| 14678 | } |
| 14679 | |
| 14680 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14681 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14682 | * But the context that is passed in is unused if the phone app is already alive. |
| 14683 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14684 | */ |
| 14685 | @VisibleForTesting |
| 14686 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14687 | mAppOps = appOps; |
| 14688 | } |
| 14689 | |
| 14690 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14691 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14692 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14693 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14694 | */ |
| 14695 | @VisibleForTesting |
| 14696 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14697 | mFeatureFlags = featureFlags; |
| 14698 | } |
| 14699 | |
| 14700 | /** |
| 14701 | * Make sure the device has required telephony feature |
| 14702 | * |
| 14703 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14704 | */ |
| 14705 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14706 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14707 | if (callingPackage == null || mPackageManager == null) { |
| 14708 | return; |
| 14709 | } |
| 14710 | |
| 14711 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14712 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14713 | Binder.getCallingUserHandle()) |
| 14714 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14715 | // Skip to check associated telephony feature, |
| 14716 | // if compatibility change is not enabled for the current process or |
| 14717 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14718 | return; |
| 14719 | } |
| 14720 | |
| 14721 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14722 | throw new UnsupportedOperationException( |
| 14723 | methodName + " is unsupported without " + telephonyFeature); |
| 14724 | } |
| 14725 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14726 | |
| 14727 | /** |
| 14728 | * Registers for the satellite communication allowed state changed. |
| 14729 | * |
| 14730 | * @param subId The subId of the subscription to register for the satellite communication |
| 14731 | * allowed state changed. |
| 14732 | * @param callback The callback to handle the satellite communication allowed |
| 14733 | * state changed event. |
| 14734 | * |
| 14735 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14736 | * |
| 14737 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14738 | */ |
| 14739 | @Override |
| 14740 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14741 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14742 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14743 | final long identity = Binder.clearCallingIdentity(); |
| 14744 | try { |
| 14745 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14746 | subId, callback); |
| 14747 | } finally { |
| 14748 | Binder.restoreCallingIdentity(identity); |
| 14749 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14750 | } |
| 14751 | |
| 14752 | /** |
| 14753 | * Unregisters for the satellite communication allowed state changed. |
| 14754 | * If callback was not registered before, the request will be ignored. |
| 14755 | * |
| 14756 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14757 | * allowed state changed. |
| 14758 | * @param callback The callback that was passed to |
| 14759 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14760 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14761 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14762 | */ |
| 14763 | @Override |
| 14764 | public void unregisterForCommunicationAllowedStateChanged( |
| 14765 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14766 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14767 | final long identity = Binder.clearCallingIdentity(); |
| 14768 | try { |
| 14769 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, |
| 14770 | callback); |
| 14771 | } finally { |
| 14772 | Binder.restoreCallingIdentity(identity); |
| 14773 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14774 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14775 | |
| 14776 | /** |
| 14777 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14778 | * |
| 14779 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14780 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14781 | * if the request is successful or an error code if the request failed. |
| 14782 | * |
| 14783 | * @throws SecurityException if the caller doesn't have required permission. |
| 14784 | */ |
| 14785 | @Override |
| 14786 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14787 | enforceModifyPermission(); |
| 14788 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14789 | final long identity = Binder.clearCallingIdentity(); |
| 14790 | try { |
| 14791 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14792 | } finally { |
| 14793 | Binder.restoreCallingIdentity(identity); |
| 14794 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14795 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14796 | |
| 14797 | /** |
| 14798 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14799 | * |
| 14800 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14801 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14802 | * |
| 14803 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14804 | */ |
| 14805 | @Override |
Hyosun | 6dbe854 | 2024-08-15 02:52:48 +0000 | [diff] [blame] | 14806 | public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) { |
| 14807 | enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14808 | final long identity = Binder.clearCallingIdentity(); |
| 14809 | try { |
| 14810 | mSatelliteController.requestSatelliteSubscriberProvisionStatus(result); |
| 14811 | } finally { |
| 14812 | Binder.restoreCallingIdentity(identity); |
| 14813 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14814 | } |
| 14815 | |
| 14816 | /** |
| 14817 | * Deliver the list of provisioned satellite subscriber ids. |
| 14818 | * |
| 14819 | * @param list List of provisioned satellite subscriber ids. |
| 14820 | * @param result The result receiver that returns whether deliver success or fail. |
| 14821 | * |
| 14822 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14823 | */ |
| 14824 | @Override |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 14825 | public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14826 | @NonNull ResultReceiver result) { |
| 14827 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14828 | final long identity = Binder.clearCallingIdentity(); |
| 14829 | try { |
| 14830 | mSatelliteController.provisionSatellite(list, result); |
| 14831 | } finally { |
| 14832 | Binder.restoreCallingIdentity(identity); |
| 14833 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14834 | } |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14835 | |
| 14836 | /** |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14837 | * Deliver the list of deprovisioned satellite subscriber ids. |
| 14838 | * |
| 14839 | * @param list List of deprovisioned satellite subscriber ids. |
| 14840 | * @param result The result receiver that returns whether deliver success or fail. |
| 14841 | * |
| 14842 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14843 | */ |
| 14844 | @Override |
| 14845 | public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
| 14846 | @NonNull ResultReceiver result) { |
| 14847 | enforceSatelliteCommunicationPermission("deprovisionSatellite"); |
| 14848 | final long identity = Binder.clearCallingIdentity(); |
| 14849 | try { |
| 14850 | mSatelliteController.deprovisionSatellite(list, result); |
| 14851 | } finally { |
| 14852 | Binder.restoreCallingIdentity(identity); |
| 14853 | } |
| 14854 | } |
| 14855 | |
Aishwarya Mallampati | a646bc1 | 2024-11-08 23:33:24 +0000 | [diff] [blame] | 14856 | |
| 14857 | /** |
| 14858 | * Inform whether application supports NTN SMS in satellite mode. |
| 14859 | * |
| 14860 | * This method is used by default messaging application to inform framework whether it supports |
| 14861 | * NTN SMS or not. |
| 14862 | * |
| 14863 | * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}. |
| 14864 | * |
| 14865 | * @throws SecurityException if the caller doesn't have required permission. |
| 14866 | */ |
| 14867 | @Override |
| 14868 | public void setNtnSmsSupported(boolean ntnSmsSupported) { |
| 14869 | enforceSatelliteCommunicationPermission("setNtnSmsSupported"); |
| 14870 | enforceSendSmsPermission(); |
Aishwarya Mallampati | dcd19f3 | 2024-11-22 17:26:54 +0000 | [diff] [blame] | 14871 | |
| 14872 | final long identity = Binder.clearCallingIdentity(); |
| 14873 | try { |
| 14874 | mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported); |
| 14875 | } finally { |
| 14876 | Binder.restoreCallingIdentity(identity); |
| 14877 | } |
Aishwarya Mallampati | a646bc1 | 2024-11-08 23:33:24 +0000 | [diff] [blame] | 14878 | } |
| 14879 | |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14880 | /** |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14881 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14882 | * value : |
| 14883 | * config_satellite_gateway_service_package and |
| 14884 | * config_satellite_carrier_roaming_esos_provisioned_class. |
| 14885 | * These values are set before sending an intent to broadcast there are any change to list of |
| 14886 | * subscriber informations. |
| 14887 | * |
| 14888 | * @param name the name is one of the following that constitute an intent. |
| 14889 | * Component package name, or component class name. |
| 14890 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14891 | */ |
| 14892 | @Override |
| 14893 | public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) { |
| 14894 | if (!mFeatureFlags.carrierRoamingNbIotNtn()) { |
| 14895 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:" |
| 14896 | + " carrierRoamingNbIotNtn is disabled"); |
| 14897 | return false; |
| 14898 | } |
| 14899 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14900 | TelephonyPermissions.enforceShellOnly( |
| 14901 | Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14903 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14904 | "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14905 | final long identity = Binder.clearCallingIdentity(); |
| 14906 | try { |
| 14907 | return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name); |
| 14908 | } finally { |
| 14909 | Binder.restoreCallingIdentity(identity); |
| 14910 | } |
| 14911 | } |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 14912 | |
| 14913 | /** |
| 14914 | * This API can be used by only CTS to override the Euicc UI component. |
| 14915 | * |
| 14916 | * @param componentName ui component to be launched for testing. {@code null} to reset. |
| 14917 | * |
| 14918 | * @hide |
| 14919 | */ |
| 14920 | @Override |
| 14921 | public void setTestEuiccUiComponent(@Nullable ComponentName componentName) { |
| 14922 | enforceModifyPermission(); |
| 14923 | log("setTestEuiccUiComponent: " + componentName); |
| 14924 | mTestEuiccUiComponent = componentName; |
| 14925 | } |
| 14926 | |
| 14927 | /** |
| 14928 | * This API can be used by only CTS to retrieve the Euicc UI component. |
| 14929 | * |
| 14930 | * @return Euicc UI component. {@code null} if not available. |
| 14931 | * @hide |
| 14932 | */ |
| 14933 | @Override |
| 14934 | @Nullable |
| 14935 | public ComponentName getTestEuiccUiComponent() { |
| 14936 | enforceReadPrivilegedPermission("getTestEuiccUiComponent"); |
| 14937 | return mTestEuiccUiComponent; |
| 14938 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14939 | |
| 14940 | /** |
| 14941 | * This API can be used only for test purpose to override the carrier roaming Ntn eligibility |
| 14942 | * |
| 14943 | * @param state to update Ntn Eligibility. |
| 14944 | * @param resetRequired to reset the overridden flag in satellite controller. |
| 14945 | * @return {@code true} if the shell command is successful, {@code false} otherwise. |
| 14946 | */ |
| 14947 | public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state, |
| 14948 | boolean resetRequired) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14949 | final long identity = Binder.clearCallingIdentity(); |
| 14950 | try { |
| 14951 | return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state, |
| 14952 | resetRequired); |
| 14953 | } finally { |
| 14954 | Binder.restoreCallingIdentity(identity); |
| 14955 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14956 | } |
jinjeong | c29c54e | 2024-11-15 08:11:18 +0000 | [diff] [blame] | 14957 | |
| 14958 | /** |
| 14959 | * Returns carrier id maps to the passing {@link CarrierIdentifier}. |
| 14960 | * |
| 14961 | * @param carrierIdentifier {@link CarrierIdentifier}. |
| 14962 | * |
| 14963 | * @return carrier id from passing {@link CarrierIdentifier} or UNKNOWN_CARRIER_ID |
| 14964 | * if the carrier cannot be identified |
| 14965 | */ |
| 14966 | public int getCarrierIdFromIdentifier(@NonNull CarrierIdentifier carrierIdentifier) { |
| 14967 | enforceReadPrivilegedPermission("getCarrierIdFromIdentifier"); |
| 14968 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 14969 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromIdentifier"); |
| 14970 | |
| 14971 | final long identity = Binder.clearCallingIdentity(); |
| 14972 | try { |
| 14973 | return CarrierResolver.getCarrierIdFromIdentifier(mApp, carrierIdentifier); |
| 14974 | } finally { |
| 14975 | Binder.restoreCallingIdentity(identity); |
| 14976 | } |
| 14977 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14978 | } |