Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS; |
| 20 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 22 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 23 | import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 24 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 26 | import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; |
| 27 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED; |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 29 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 30 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 31 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 32 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 34 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 35 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 36 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 37 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 38 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 39 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 40 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 41 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 42 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 44 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 45 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 46 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 47 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 48 | import android.compat.annotation.ChangeId; |
| 49 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 50 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 51 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 52 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.content.Context; |
| 54 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 55 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 56 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 57 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.net.Uri; |
| 59 | import android.os.AsyncResult; |
| 60 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 61 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 62 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 63 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 65 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 66 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 67 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.os.Looper; |
| 69 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 71 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 72 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 74 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 75 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 76 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 77 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 78 | import android.os.SystemClock; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 79 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 81 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 82 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 83 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 84 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 85 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 86 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 87 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 88 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 89 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 90 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 91 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 92 | import android.telephony.AccessNetworkConstants; |
| 93 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 94 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 95 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 96 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 97 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 98 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 99 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 100 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 101 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 102 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 103 | import android.telephony.CellIdentityCdma; |
| 104 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 106 | import android.telephony.CellInfoGsm; |
| 107 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 108 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 109 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 110 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 111 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 112 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 113 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 114 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 115 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 116 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 117 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 118 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 119 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 120 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 121 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 122 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 123 | import android.telephony.SignalStrengthUpdateRequest; |
| 124 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 125 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 126 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 127 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 128 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 129 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 130 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 131 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 132 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 133 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 134 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 135 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 136 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 137 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 138 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 139 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 140 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 141 | import android.telephony.gba.GbaAuthRequest; |
| 142 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 143 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 144 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 145 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 146 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 147 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 154 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 155 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 156 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 157 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 158 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 160 | import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 164 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 165 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 166 | import android.telephony.satellite.NtnSignalStrength; |
| 167 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame^] | 168 | import android.telephony.satellite.ProvisionSubscriberId; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 171 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 173 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 175 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 176 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 178 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 180 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 181 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 182 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 183 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 198 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 215 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 216 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 218 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 222 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 225 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 228 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 229 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 230 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 231 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 232 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 233 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 234 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 235 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 236 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 238 | import com.android.internal.telephony.uicc.IccIoResult; |
| 239 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 243 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 244 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 245 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 246 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 247 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 248 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 249 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 250 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 251 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 252 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 253 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 254 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 255 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 256 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 257 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 258 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 259 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 260 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 261 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 262 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 263 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 264 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 265 | import com.android.services.telephony.TelecomAccountRegistry; |
| 266 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 267 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 268 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 269 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 270 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 271 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 272 | import java.io.IOException; |
| 273 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 274 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 276 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 277 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 278 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 279 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 280 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 281 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 282 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 283 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 284 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 285 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 286 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 287 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 288 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 289 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 290 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * Implementation of the ITelephony interface. |
| 294 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 295 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 297 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 298 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 299 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 300 | |
| 301 | // Message codes used with mMainThreadHandler |
| 302 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 303 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 304 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 305 | private static final int CMD_OPEN_CHANNEL = 9; |
| 306 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 307 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 308 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 309 | private static final int CMD_NV_READ_ITEM = 13; |
| 310 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 311 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 312 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 313 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 314 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 315 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 316 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 317 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 318 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 319 | private static final int CMD_SEND_ENVELOPE = 25; |
| 320 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 321 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 322 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 323 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 324 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 325 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 326 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 327 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 328 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 329 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 330 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 331 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 332 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 333 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 334 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 335 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 336 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 337 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 338 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 339 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 340 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 341 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 342 | private static final int CMD_SWITCH_SLOTS = 50; |
| 343 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 344 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 345 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 346 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 347 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 348 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 349 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 350 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 351 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 352 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 353 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 354 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 355 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 356 | private static final int CMD_MODEM_REBOOT = 64; |
| 357 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 358 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 359 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 360 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 361 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 362 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 363 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 364 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 365 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 366 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 367 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 368 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 369 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 370 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 371 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 372 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 373 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 374 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 375 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 376 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 377 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 378 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 379 | private static final int CMD_GET_CALL_WAITING = 87; |
| 380 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 381 | private static final int CMD_SET_CALL_WAITING = 89; |
| 382 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 383 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 384 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 385 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 386 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 387 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 388 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 389 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 390 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 391 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 392 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 393 | private static final int CMD_SET_SIM_POWER = 101; |
| 394 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 395 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 396 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 397 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 398 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 399 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 400 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 401 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 402 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 403 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 404 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 405 | private static final int CMD_ENABLE_VONR = 113; |
| 406 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 407 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 408 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 409 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 410 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 411 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 412 | // Parameters of select command. |
| 413 | private static final int SELECT_COMMAND = 0xA4; |
| 414 | private static final int SELECT_P1 = 0x04; |
| 415 | private static final int SELECT_P2 = 0; |
| 416 | private static final int SELECT_P3 = 0x10; |
| 417 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 418 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 419 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 420 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 421 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 422 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 423 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 424 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | /** The singleton instance. */ |
| 426 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 427 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 429 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 430 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 431 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 432 | private final CallManager mCM; |
| 433 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 434 | |
| 435 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 436 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 437 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 438 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 439 | private final SharedPreferences mTelephonySharedPreferences; |
| 440 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 441 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 442 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 443 | private PackageManager mPackageManager; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 444 | private final int mVendorApiLevel; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 446 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 447 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 448 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 449 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 450 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 451 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 452 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 453 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 454 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 455 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 456 | // String to store multi SIM allowed |
| 457 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 458 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 459 | // The AID of ISD-R. |
| 460 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 461 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 462 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 463 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 464 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 465 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 466 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 467 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 468 | private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 469 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 470 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 471 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 472 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 473 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 474 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 475 | */ |
| 476 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 477 | "reset_network_erase_modem_config_enabled"; |
| 478 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 479 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 480 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 481 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 482 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 483 | /** |
| 484 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 485 | * one ICCID active at the same time. |
| 486 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 487 | * |
| 488 | * @hide |
| 489 | */ |
| 490 | @ChangeId |
| 491 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 492 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 493 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 494 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 495 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 496 | * operation fails. |
| 497 | */ |
| 498 | @ChangeId |
| 499 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 500 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 501 | |
| 502 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | * A request object to use for transmitting data to an ICC. |
| 504 | */ |
| 505 | private static final class IccAPDUArgument { |
| 506 | public int channel, cla, command, p1, p2, p3; |
| 507 | public String data; |
| 508 | |
| 509 | public IccAPDUArgument(int channel, int cla, int command, |
| 510 | int p1, int p2, int p3, String data) { |
| 511 | this.channel = channel; |
| 512 | this.cla = cla; |
| 513 | this.command = command; |
| 514 | this.p1 = p1; |
| 515 | this.p2 = p2; |
| 516 | this.p3 = p3; |
| 517 | this.data = data; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 522 | * A request object to use for transmitting data to an ICC. |
| 523 | */ |
| 524 | private static final class ManualNetworkSelectionArgument { |
| 525 | public OperatorInfo operatorInfo; |
| 526 | public boolean persistSelection; |
| 527 | |
| 528 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 529 | this.operatorInfo = operatorInfo; |
| 530 | this.persistSelection = persistSelection; |
| 531 | } |
| 532 | } |
| 533 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 534 | private static final class PurchasePremiumCapabilityArgument { |
| 535 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 536 | public @NonNull IIntegerConsumer callback; |
| 537 | |
| 538 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 539 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 540 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 541 | this.callback = callback; |
| 542 | } |
| 543 | } |
| 544 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 545 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 546 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 547 | * request after sending. The main thread will notify the request when it is complete. |
| 548 | */ |
| 549 | private static final class MainThreadRequest { |
| 550 | /** The argument to use for the request */ |
| 551 | public Object argument; |
| 552 | /** The result of the request that is run on the main thread */ |
| 553 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 554 | // The subscriber id that this request applies to. Defaults to |
| 555 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 556 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 557 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 558 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 559 | public Phone phone; |
| 560 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 561 | public WorkSource workSource; |
| 562 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 563 | public MainThreadRequest(Object argument) { |
| 564 | this.argument = argument; |
| 565 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 566 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 567 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 568 | this.argument = argument; |
| 569 | if (phone != null) { |
| 570 | this.phone = phone; |
| 571 | } |
| 572 | this.workSource = workSource; |
| 573 | } |
| 574 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 575 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 576 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 577 | if (subId != null) { |
| 578 | this.subId = subId; |
| 579 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 580 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 581 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 584 | private static final class IncomingThirdPartyCallArgs { |
| 585 | public final ComponentName component; |
| 586 | public final String callId; |
| 587 | public final String callerDisplayName; |
| 588 | |
| 589 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 590 | String callerDisplayName) { |
| 591 | this.component = component; |
| 592 | this.callId = callId; |
| 593 | this.callerDisplayName = callerDisplayName; |
| 594 | } |
| 595 | } |
| 596 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 597 | /** |
| 598 | * A handler that processes messages on the main thread in the phone process. Since many |
| 599 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 600 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 601 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 602 | * on, which will be notified when the operation completes and will contain the result of the |
| 603 | * request. |
| 604 | * |
| 605 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 606 | * note that request.result must be set to something non-null for the calling thread to |
| 607 | * unblock. |
| 608 | */ |
| 609 | private final class MainThreadHandler extends Handler { |
| 610 | @Override |
| 611 | public void handleMessage(Message msg) { |
| 612 | MainThreadRequest request; |
| 613 | Message onCompleted; |
| 614 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 615 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 616 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 617 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 618 | |
| 619 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | case CMD_HANDLE_USSD_REQUEST: { |
| 621 | request = (MainThreadRequest) msg.obj; |
| 622 | final Phone phone = getPhoneFromRequest(request); |
| 623 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 624 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 625 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 626 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | if (!isUssdApiAllowed(request.subId)) { |
| 628 | // Carrier does not support use of this API, return failure. |
| 629 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 630 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 631 | Bundle returnData = new Bundle(); |
| 632 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 633 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 634 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | request.result = true; |
| 636 | notifyRequester(request); |
| 637 | return; |
| 638 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 639 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 640 | try { |
| 641 | request.result = phone != null |
| 642 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 643 | } catch (CallStateException cse) { |
| 644 | request.result = false; |
| 645 | } |
| 646 | // Wake up the requesting thread |
| 647 | notifyRequester(request); |
| 648 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 651 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 652 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 653 | final Phone phone = getPhoneFromRequest(request); |
| 654 | request.result = phone != null ? |
| 655 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 656 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 657 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 658 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 659 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 662 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 665 | uiccPort = getUiccPortFromRequest(request); |
| 666 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 667 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 668 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 669 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 670 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 672 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 673 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 674 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 675 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 676 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 677 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | break; |
| 679 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | ar = (AsyncResult) msg.obj; |
| 682 | request = (MainThreadRequest) ar.userObj; |
| 683 | if (ar.exception == null && ar.result != null) { |
| 684 | request.result = ar.result; |
| 685 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 686 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | if (ar.result == null) { |
| 688 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 689 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | } else { |
| 693 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 694 | } |
| 695 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 696 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 697 | break; |
| 698 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 699 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 700 | request = (MainThreadRequest) msg.obj; |
| 701 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 702 | uiccPort = getUiccPortFromRequest(request); |
| 703 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 704 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 705 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 706 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | } else { |
| 708 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 709 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 710 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 711 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 712 | iccArgument.p2, |
| 713 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 714 | } |
| 715 | break; |
| 716 | |
| 717 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 718 | ar = (AsyncResult) msg.obj; |
| 719 | request = (MainThreadRequest) ar.userObj; |
| 720 | if (ar.exception == null && ar.result != null) { |
| 721 | request.result = ar.result; |
| 722 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 723 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 724 | if (ar.result == null) { |
| 725 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 726 | } else if (ar.exception instanceof CommandException) { |
| 727 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 728 | ar.exception); |
| 729 | } else { |
| 730 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 731 | } |
| 732 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 733 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case CMD_EXCHANGE_SIM_IO: |
| 737 | request = (MainThreadRequest) msg.obj; |
| 738 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 739 | uiccPort = getUiccPortFromRequest(request); |
| 740 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 742 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 744 | } else { |
| 745 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 746 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 747 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 748 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 749 | iccArgument.data, onCompleted); |
| 750 | } |
| 751 | break; |
| 752 | |
| 753 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 754 | ar = (AsyncResult) msg.obj; |
| 755 | request = (MainThreadRequest) ar.userObj; |
| 756 | if (ar.exception == null && ar.result != null) { |
| 757 | request.result = ar.result; |
| 758 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 759 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 760 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 761 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 762 | break; |
| 763 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 764 | case CMD_SEND_ENVELOPE: |
| 765 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 766 | uiccPort = getUiccPortFromRequest(request); |
| 767 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 768 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 769 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 770 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 771 | } else { |
| 772 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 773 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 774 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_SEND_ENVELOPE_DONE: |
| 778 | ar = (AsyncResult) msg.obj; |
| 779 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 780 | if (ar.exception == null && ar.result != null) { |
| 781 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 782 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 783 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 784 | if (ar.result == null) { |
| 785 | loge("sendEnvelopeWithStatus: Empty response"); |
| 786 | } else if (ar.exception instanceof CommandException) { |
| 787 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 788 | ar.exception); |
| 789 | } else { |
| 790 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 791 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 792 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 793 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 794 | break; |
| 795 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 796 | case CMD_OPEN_CHANNEL: |
| 797 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 798 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 799 | IccLogicalChannelRequest openChannelRequest = |
| 800 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 801 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 802 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 803 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 804 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 805 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 806 | } else { |
| 807 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 808 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 809 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 810 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 811 | break; |
| 812 | |
| 813 | case EVENT_OPEN_CHANNEL_DONE: |
| 814 | ar = (AsyncResult) msg.obj; |
| 815 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 816 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 817 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 818 | int[] result = (int[]) ar.result; |
| 819 | int channelId = result[0]; |
| 820 | byte[] selectResponse = null; |
| 821 | if (result.length > 1) { |
| 822 | selectResponse = new byte[result.length - 1]; |
| 823 | for (int i = 1; i < result.length; ++i) { |
| 824 | selectResponse[i - 1] = (byte) result[i]; |
| 825 | } |
| 826 | } |
| 827 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 828 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 829 | |
| 830 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 831 | if (uiccPort == null) { |
| 832 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 833 | } else { |
| 834 | IccLogicalChannelRequest channelRequest = |
| 835 | (IccLogicalChannelRequest) request.argument; |
| 836 | channelRequest.channel = channelId; |
| 837 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 838 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 839 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 840 | if (ar.result == null) { |
| 841 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 842 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 843 | if (ar.exception != null) { |
| 844 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 845 | } |
| 846 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 847 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 848 | if (ar.exception instanceof CommandException) { |
| 849 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 850 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 851 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 852 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 853 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 854 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 858 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 859 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 860 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 861 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 862 | break; |
| 863 | |
| 864 | case CMD_CLOSE_CHANNEL: |
| 865 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 866 | uiccPort = getUiccPortFromRequest(request); |
| 867 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 868 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 869 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 870 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 871 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 872 | } else { |
| 873 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 874 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 875 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 879 | ar = (AsyncResult) msg.obj; |
| 880 | request = (MainThreadRequest) ar.userObj; |
| 881 | if (ar.exception == null) { |
| 882 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 883 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 884 | if (uiccPort == null) { |
| 885 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 886 | } else { |
| 887 | final int channelId = (Integer) request.argument; |
| 888 | uiccPort.onLogicalChannelClosed(channelId); |
| 889 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 890 | } else { |
| 891 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 892 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 893 | if (ar.exception instanceof CommandException) { |
| 894 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 895 | CommandException.Error error = |
| 896 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 897 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 898 | // should only throw exceptions from the binder threads. |
| 899 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 900 | "iccCloseLogicalChannel: invalid argument "); |
| 901 | } |
| 902 | } else { |
| 903 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 904 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 905 | request.result = (exception != null) ? exception : |
| 906 | new IllegalStateException( |
| 907 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 908 | } |
| 909 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 910 | break; |
| 911 | |
| 912 | case CMD_NV_READ_ITEM: |
| 913 | request = (MainThreadRequest) msg.obj; |
| 914 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 915 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 916 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 920 | ar = (AsyncResult) msg.obj; |
| 921 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 922 | if (ar.exception == null && ar.result != null) { |
| 923 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 924 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 925 | request.result = ""; |
| 926 | if (ar.result == null) { |
| 927 | loge("nvReadItem: Empty response"); |
| 928 | } else if (ar.exception instanceof CommandException) { |
| 929 | loge("nvReadItem: CommandException: " + |
| 930 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 931 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 932 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 933 | } |
| 934 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 935 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 936 | break; |
| 937 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 938 | case CMD_NV_WRITE_ITEM: |
| 939 | request = (MainThreadRequest) msg.obj; |
| 940 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 941 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 942 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 943 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 944 | break; |
| 945 | |
| 946 | case EVENT_NV_WRITE_ITEM_DONE: |
| 947 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 948 | break; |
| 949 | |
| 950 | case CMD_NV_WRITE_CDMA_PRL: |
| 951 | request = (MainThreadRequest) msg.obj; |
| 952 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 953 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 954 | break; |
| 955 | |
| 956 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 957 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 958 | break; |
| 959 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 960 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 961 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 962 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 963 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 964 | break; |
| 965 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 966 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 967 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 968 | break; |
| 969 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 970 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 971 | request = (MainThreadRequest) msg.obj; |
| 972 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 973 | request); |
| 974 | Phone phone = getPhoneFromRequest(request); |
| 975 | if (phone != null) { |
| 976 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 977 | } else { |
| 978 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 979 | request.result = false; |
| 980 | notifyRequester(request); |
| 981 | } |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | if (ar.exception == null && ar.result != null) { |
| 989 | request.result = ar.result; |
| 990 | } else { |
| 991 | // request.result must be set to something non-null |
| 992 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 993 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 994 | request.result = ar.result; |
| 995 | } else { |
| 996 | request.result = false; |
| 997 | } |
| 998 | if (ar.result == null) { |
| 999 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1000 | } else if (ar.exception instanceof CommandException) { |
| 1001 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1002 | + ar.exception); |
| 1003 | } else { |
| 1004 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1005 | } |
| 1006 | } |
| 1007 | notifyRequester(request); |
| 1008 | break; |
| 1009 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1010 | case CMD_IS_VONR_ENABLED: { |
| 1011 | request = (MainThreadRequest) msg.obj; |
| 1012 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1013 | request); |
| 1014 | Phone phone = getPhoneFromRequest(request); |
| 1015 | if (phone != null) { |
| 1016 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1017 | } else { |
| 1018 | loge("isVoNrEnabled: No phone object"); |
| 1019 | request.result = false; |
| 1020 | notifyRequester(request); |
| 1021 | } |
| 1022 | break; |
| 1023 | } |
| 1024 | |
| 1025 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1026 | ar = (AsyncResult) msg.obj; |
| 1027 | request = (MainThreadRequest) ar.userObj; |
| 1028 | if (ar.exception == null && ar.result != null) { |
| 1029 | request.result = ar.result; |
| 1030 | } else { |
| 1031 | // request.result must be set to something non-null |
| 1032 | // for the calling thread to unblock |
| 1033 | if (ar.result != null) { |
| 1034 | request.result = ar.result; |
| 1035 | } else { |
| 1036 | request.result = false; |
| 1037 | } |
| 1038 | if (ar.result == null) { |
| 1039 | loge("isVoNrEnabled: Empty response"); |
| 1040 | } else if (ar.exception instanceof CommandException) { |
| 1041 | loge("isVoNrEnabled: CommandException: " |
| 1042 | + ar.exception); |
| 1043 | } else { |
| 1044 | loge("isVoNrEnabled: Unknown exception"); |
| 1045 | } |
| 1046 | } |
| 1047 | notifyRequester(request); |
| 1048 | break; |
| 1049 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1050 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1051 | request = (MainThreadRequest) msg.obj; |
| 1052 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1053 | Phone phone = getPhoneFromRequest(request); |
| 1054 | if (phone != null) { |
| 1055 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1056 | request.workSource); |
| 1057 | } else { |
| 1058 | loge("enableNrDualConnectivity: No phone object"); |
| 1059 | request.result = |
| 1060 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1061 | notifyRequester(request); |
| 1062 | } |
| 1063 | break; |
| 1064 | } |
| 1065 | |
| 1066 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
| 1069 | if (ar.exception == null) { |
| 1070 | request.result = |
| 1071 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1072 | } else { |
| 1073 | request.result = |
| 1074 | TelephonyManager |
| 1075 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1076 | if (ar.exception instanceof CommandException) { |
| 1077 | CommandException.Error error = |
| 1078 | ((CommandException) (ar.exception)).getCommandError(); |
| 1079 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1080 | request.result = |
| 1081 | TelephonyManager |
| 1082 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1083 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1084 | request.result = |
| 1085 | TelephonyManager |
| 1086 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1087 | } |
| 1088 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1089 | + ar.exception); |
| 1090 | } else { |
| 1091 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1092 | } |
| 1093 | } |
| 1094 | notifyRequester(request); |
| 1095 | break; |
| 1096 | } |
| 1097 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1098 | case CMD_ENABLE_VONR: { |
| 1099 | request = (MainThreadRequest) msg.obj; |
| 1100 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1101 | Phone phone = getPhoneFromRequest(request); |
| 1102 | if (phone != null) { |
| 1103 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1104 | request.workSource); |
| 1105 | } else { |
| 1106 | loge("setVoNrEnabled: No phone object"); |
| 1107 | request.result = |
| 1108 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1109 | notifyRequester(request); |
| 1110 | } |
| 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | case EVENT_ENABLE_VONR_DONE: { |
| 1115 | ar = (AsyncResult) msg.obj; |
| 1116 | request = (MainThreadRequest) ar.userObj; |
| 1117 | if (ar.exception == null) { |
| 1118 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1119 | } else { |
| 1120 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1121 | if (ar.exception instanceof CommandException) { |
| 1122 | CommandException.Error error = |
| 1123 | ((CommandException) (ar.exception)).getCommandError(); |
| 1124 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1125 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1126 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1127 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1128 | } else { |
| 1129 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1130 | } |
| 1131 | loge("setVoNrEnabled" + ": CommandException: " |
| 1132 | + ar.exception); |
| 1133 | } else { |
| 1134 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1135 | } |
| 1136 | } |
| 1137 | notifyRequester(request); |
| 1138 | break; |
| 1139 | } |
| 1140 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1141 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1142 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1143 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1144 | request); |
| 1145 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1146 | break; |
| 1147 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1148 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1149 | ar = (AsyncResult) msg.obj; |
| 1150 | request = (MainThreadRequest) ar.userObj; |
| 1151 | if (ar.exception == null && ar.result != null) { |
| 1152 | request.result = ar.result; // Integer |
| 1153 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1154 | // request.result must be set to something non-null |
| 1155 | // for the calling thread to unblock |
| 1156 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1157 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1158 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1159 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1160 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1161 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1162 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1163 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1164 | } |
| 1165 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1166 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1167 | break; |
| 1168 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1169 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1170 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1171 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1172 | request); |
| 1173 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1174 | (Pair<Integer, Long>) request.argument; |
| 1175 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1176 | reasonWithNetworkTypes.first, |
| 1177 | reasonWithNetworkTypes.second, |
| 1178 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1179 | break; |
| 1180 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1181 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1182 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1183 | break; |
| 1184 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1185 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1186 | request = (MainThreadRequest) msg.obj; |
| 1187 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1188 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1189 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1190 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1191 | break; |
| 1192 | |
| 1193 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1194 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1195 | break; |
| 1196 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1197 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1198 | request = (MainThreadRequest) msg.obj; |
| 1199 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1200 | request); |
| 1201 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1202 | break; |
| 1203 | |
| 1204 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1205 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1206 | break; |
| 1207 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1208 | case CMD_PERFORM_NETWORK_SCAN: |
| 1209 | request = (MainThreadRequest) msg.obj; |
| 1210 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1211 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1212 | break; |
| 1213 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1215 | request = (MainThreadRequest) msg.obj; |
| 1216 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1218 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1219 | request.argument; |
| 1220 | int callForwardingReason = args.first; |
| 1221 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1222 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | } |
| 1224 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | ar = (AsyncResult) msg.obj; |
| 1226 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1228 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1229 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1233 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1234 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1235 | // any service for voice call. |
| 1236 | if ((callForwardInfo.serviceClass |
| 1237 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1238 | callForwardingInfo = new CallForwardingInfo( |
| 1239 | callForwardInfo.status |
| 1240 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | callForwardInfo.reason, |
| 1242 | callForwardInfo.number, |
| 1243 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | break; |
| 1245 | } |
| 1246 | } |
| 1247 | // Didn't find a call forward info for voice call. |
| 1248 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1250 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1251 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | } else { |
| 1254 | if (ar.result == null) { |
| 1255 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1256 | } |
| 1257 | if (ar.exception != null) { |
| 1258 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1259 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1260 | int errorCode = TelephonyManager |
| 1261 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | if (ar.exception instanceof CommandException) { |
| 1263 | CommandException.Error error = |
| 1264 | ((CommandException) (ar.exception)).getCommandError(); |
| 1265 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1266 | errorCode = TelephonyManager |
| 1267 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1269 | errorCode = TelephonyManager |
| 1270 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | } |
| 1272 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1273 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1278 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | request = (MainThreadRequest) msg.obj; |
| 1280 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1283 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1284 | request.argument).first; |
| 1285 | request.phone.setCallForwardingOption( |
| 1286 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1287 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1288 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | callForwardingInfoToSet.getReason(), |
| 1290 | callForwardingInfoToSet.getNumber(), |
| 1291 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1292 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1295 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1296 | ar = (AsyncResult) msg.obj; |
| 1297 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | Consumer<Integer> callback = |
| 1299 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1300 | request.argument).second; |
| 1301 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1303 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1304 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | if (ar.exception instanceof CommandException) { |
| 1306 | CommandException.Error error = |
| 1307 | ((CommandException) (ar.exception)).getCommandError(); |
| 1308 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1309 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1310 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1312 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1313 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | callback.accept(errorCode); |
| 1317 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1318 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1320 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1321 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1323 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | request = (MainThreadRequest) msg.obj; |
| 1325 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1326 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1327 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1328 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1330 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | ar = (AsyncResult) msg.obj; |
| 1332 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1333 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1334 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1336 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | // Service Class is a bit mask per 3gpp 27.007. |
| 1338 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1339 | if (callForwardResults.length > 1 |
| 1340 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1342 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1343 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1344 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1346 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | } |
| 1348 | } else { |
| 1349 | if (ar.result == null) { |
| 1350 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1351 | } |
| 1352 | if (ar.exception != null) { |
| 1353 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1354 | } |
| 1355 | if (ar.exception instanceof CommandException) { |
| 1356 | CommandException.Error error = |
| 1357 | ((CommandException) (ar.exception)).getCommandError(); |
| 1358 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1359 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1361 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1362 | callWaitingStatus = |
| 1363 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | } |
| 1365 | } |
| 1366 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1367 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1368 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1369 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1370 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1371 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | request = (MainThreadRequest) msg.obj; |
| 1373 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1374 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1375 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1376 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1377 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1378 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1379 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1380 | ar = (AsyncResult) msg.obj; |
| 1381 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1382 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1383 | Consumer<Integer> callback = |
| 1384 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1385 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1386 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1387 | if (ar.exception instanceof CommandException) { |
| 1388 | CommandException.Error error = |
| 1389 | ((CommandException) (ar.exception)).getCommandError(); |
| 1390 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1391 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1392 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1393 | callback.accept( |
| 1394 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1395 | } else { |
| 1396 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1397 | } |
| 1398 | } else { |
| 1399 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1400 | } |
| 1401 | } else { |
| 1402 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1403 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1404 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1405 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1406 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1407 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1408 | ar = (AsyncResult) msg.obj; |
| 1409 | request = (MainThreadRequest) ar.userObj; |
| 1410 | CellNetworkScanResult cellScanResult; |
| 1411 | if (ar.exception == null && ar.result != null) { |
| 1412 | cellScanResult = new CellNetworkScanResult( |
| 1413 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1414 | (List<OperatorInfo>) ar.result); |
| 1415 | } else { |
| 1416 | if (ar.result == null) { |
| 1417 | loge("getCellNetworkScanResults: Empty response"); |
| 1418 | } |
| 1419 | if (ar.exception != null) { |
| 1420 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1421 | } |
| 1422 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1423 | if (ar.exception instanceof CommandException) { |
| 1424 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1425 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1426 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1427 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1428 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1429 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1430 | } |
| 1431 | } |
| 1432 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1433 | } |
| 1434 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1435 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1436 | break; |
| 1437 | |
| 1438 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1439 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1440 | ManualNetworkSelectionArgument selArg = |
| 1441 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1442 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1443 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1444 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1445 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1446 | break; |
| 1447 | |
| 1448 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1449 | ar = (AsyncResult) msg.obj; |
| 1450 | request = (MainThreadRequest) ar.userObj; |
| 1451 | if (ar.exception == null) { |
| 1452 | request.result = true; |
| 1453 | } else { |
| 1454 | request.result = false; |
| 1455 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1456 | } |
| 1457 | notifyRequester(request); |
| 1458 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1459 | break; |
| 1460 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1461 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1462 | request = (MainThreadRequest) msg.obj; |
| 1463 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1464 | if (defaultPhone != null) { |
| 1465 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1466 | } else { |
| 1467 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1468 | Bundle bundle = new Bundle(); |
| 1469 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1470 | new ModemActivityInfo(0, 0, 0, |
| 1471 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1472 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1473 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1474 | break; |
| 1475 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1476 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1477 | ar = (AsyncResult) msg.obj; |
| 1478 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1479 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1480 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1481 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1482 | if (mLastModemActivityInfo == null) { |
| 1483 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1484 | mLastModemActivitySpecificInfo[0] = |
| 1485 | new ActivityStatsTechSpecificInfo( |
| 1486 | 0, |
| 1487 | 0, |
| 1488 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1489 | 0); |
| 1490 | mLastModemActivityInfo = |
| 1491 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1492 | } |
| 1493 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1494 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1495 | // Update the last modem activity info and the result of the request. |
| 1496 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1497 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1498 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1499 | } else { |
| 1500 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1501 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1502 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1503 | // We don't want to return mLastModemActivityInfo which is updated |
| 1504 | // inside mergeModemActivityInfo() |
| 1505 | ret = new ModemActivityInfo( |
| 1506 | mLastModemActivityInfo.getTimestampMillis(), |
| 1507 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1508 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1509 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1510 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1511 | } else { |
| 1512 | if (ar.result == null) { |
| 1513 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1514 | error = TelephonyManager.ModemActivityInfoException |
| 1515 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1516 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1517 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1518 | error = TelephonyManager.ModemActivityInfoException |
| 1519 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1520 | } else { |
| 1521 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1522 | error = TelephonyManager.ModemActivityInfoException |
| 1523 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1524 | } |
| 1525 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1526 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1527 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1528 | bundle.putParcelable( |
| 1529 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1530 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1531 | } else { |
| 1532 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1533 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1534 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1535 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1536 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1537 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1538 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1539 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1540 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1541 | CarrierRestrictionRules argument = |
| 1542 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1543 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1544 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1545 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1546 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1547 | |
| 1548 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1549 | ar = (AsyncResult) msg.obj; |
| 1550 | request = (MainThreadRequest) ar.userObj; |
| 1551 | if (ar.exception == null && ar.result != null) { |
| 1552 | request.result = ar.result; |
| 1553 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1554 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1555 | if (ar.exception instanceof CommandException) { |
| 1556 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1557 | CommandException.Error error = |
| 1558 | ((CommandException) (ar.exception)).getCommandError(); |
| 1559 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1560 | request.result = |
| 1561 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1562 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1563 | } else { |
| 1564 | loge("setAllowedCarriers: Unknown exception"); |
| 1565 | } |
| 1566 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1567 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1568 | break; |
| 1569 | |
| 1570 | case CMD_GET_ALLOWED_CARRIERS: |
| 1571 | request = (MainThreadRequest) msg.obj; |
| 1572 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1573 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1574 | break; |
| 1575 | |
| 1576 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1577 | ar = (AsyncResult) msg.obj; |
| 1578 | request = (MainThreadRequest) ar.userObj; |
| 1579 | if (ar.exception == null && ar.result != null) { |
| 1580 | request.result = ar.result; |
| 1581 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1582 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1583 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1584 | if (ar.result == null) { |
| 1585 | loge("getAllowedCarriers: Empty response"); |
| 1586 | } else if (ar.exception instanceof CommandException) { |
| 1587 | loge("getAllowedCarriers: CommandException: " + |
| 1588 | ar.exception); |
| 1589 | } else { |
| 1590 | loge("getAllowedCarriers: Unknown exception"); |
| 1591 | } |
| 1592 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1593 | if (request.argument != null) { |
| 1594 | // This is for the implementation of carrierRestrictionStatus. |
| 1595 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1596 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1597 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1598 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1599 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1600 | CarrierRestrictionRules carrierRestrictionRules = |
| 1601 | (CarrierRestrictionRules) ar.result; |
| 1602 | int carrierId = -1; |
| 1603 | try { |
| 1604 | CarrierIdentifier carrierIdentifier = |
| 1605 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1606 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1607 | carrierIdentifier); |
| 1608 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1609 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1610 | } |
| 1611 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1612 | int restrictedStatus = |
| 1613 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1614 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1615 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1616 | lockStatus = TelephonyManager |
| 1617 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1618 | } |
| 1619 | } else { |
| 1620 | Rlog.e(LOG_TAG, |
| 1621 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1622 | } |
| 1623 | callback.accept(lockStatus); |
| 1624 | } else { |
| 1625 | // This is for the implementation of getAllowedCarriers. |
| 1626 | notifyRequester(request); |
| 1627 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1628 | break; |
| 1629 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1630 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1631 | ar = (AsyncResult) msg.obj; |
| 1632 | request = (MainThreadRequest) ar.userObj; |
| 1633 | if (ar.exception == null && ar.result != null) { |
| 1634 | request.result = ar.result; |
| 1635 | } else { |
| 1636 | request.result = new IllegalArgumentException( |
| 1637 | "Failed to retrieve Forbidden Plmns"); |
| 1638 | if (ar.result == null) { |
| 1639 | loge("getForbiddenPlmns: Empty response"); |
| 1640 | } else { |
| 1641 | loge("getForbiddenPlmns: Unknown exception"); |
| 1642 | } |
| 1643 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1644 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1645 | break; |
| 1646 | |
| 1647 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1648 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1649 | uiccPort = getUiccPortFromRequest(request); |
| 1650 | if (uiccPort == null) { |
| 1651 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1652 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1653 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1654 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1655 | break; |
| 1656 | } |
| 1657 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1658 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1659 | if (uiccApp == null) { |
| 1660 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1661 | + appType); |
| 1662 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
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 | } else { |
| 1666 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1667 | + " specified type -- " + appType); |
| 1668 | } |
| 1669 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1670 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1671 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1672 | break; |
| 1673 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1674 | case CMD_SWITCH_SLOTS: |
| 1675 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1676 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1677 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1678 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | |
| 1681 | case EVENT_SWITCH_SLOTS_DONE: |
| 1682 | ar = (AsyncResult) msg.obj; |
| 1683 | request = (MainThreadRequest) ar.userObj; |
| 1684 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1685 | notifyRequester(request); |
| 1686 | break; |
| 1687 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1688 | request = (MainThreadRequest) msg.obj; |
| 1689 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1690 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1691 | break; |
| 1692 | |
| 1693 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1694 | ar = (AsyncResult) msg.obj; |
| 1695 | request = (MainThreadRequest) ar.userObj; |
| 1696 | if (ar.exception != null) { |
| 1697 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1698 | } else { |
| 1699 | int mode = ((int[]) ar.result)[0]; |
| 1700 | if (mode == 0) { |
| 1701 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1702 | } else { |
| 1703 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1704 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1705 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1706 | notifyRequester(request); |
| 1707 | break; |
| 1708 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1709 | request = (MainThreadRequest) msg.obj; |
| 1710 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1711 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1712 | break; |
| 1713 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1714 | ar = (AsyncResult) msg.obj; |
| 1715 | request = (MainThreadRequest) ar.userObj; |
| 1716 | if (ar.exception != null) { |
| 1717 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1718 | } else { |
| 1719 | request.result = ((int[]) ar.result)[0]; |
| 1720 | } |
| 1721 | notifyRequester(request); |
| 1722 | break; |
| 1723 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1724 | request = (MainThreadRequest) msg.obj; |
| 1725 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1726 | int mode = (int) request.argument; |
| 1727 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1728 | break; |
| 1729 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1730 | ar = (AsyncResult) msg.obj; |
| 1731 | request = (MainThreadRequest) ar.userObj; |
| 1732 | request.result = ar.exception == null; |
| 1733 | notifyRequester(request); |
| 1734 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1735 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1736 | request = (MainThreadRequest) msg.obj; |
| 1737 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1738 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1739 | break; |
| 1740 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1741 | ar = (AsyncResult) msg.obj; |
| 1742 | request = (MainThreadRequest) ar.userObj; |
| 1743 | if (ar.exception != null) { |
| 1744 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1745 | } else { |
| 1746 | request.result = ((int[]) ar.result)[0]; |
| 1747 | } |
| 1748 | notifyRequester(request); |
| 1749 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1750 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1751 | request = (MainThreadRequest) msg.obj; |
| 1752 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1753 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1754 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1755 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1756 | break; |
| 1757 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1758 | ar = (AsyncResult) msg.obj; |
| 1759 | request = (MainThreadRequest) ar.userObj; |
| 1760 | request.result = ar.exception == null; |
| 1761 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1762 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1763 | case CMD_GET_ALL_CELL_INFO: |
| 1764 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1765 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1766 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1767 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1768 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1769 | ar = (AsyncResult) msg.obj; |
| 1770 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1771 | // If a timeout occurs, the response will be null |
| 1772 | request.result = (ar.exception == null && ar.result != null) |
| 1773 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1774 | synchronized (request) { |
| 1775 | request.notifyAll(); |
| 1776 | } |
| 1777 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1778 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1779 | request = (MainThreadRequest) msg.obj; |
| 1780 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1781 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1782 | break; |
| 1783 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1784 | ar = (AsyncResult) msg.obj; |
| 1785 | request = (MainThreadRequest) ar.userObj; |
| 1786 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1787 | try { |
| 1788 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1789 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1790 | cb.onError( |
| 1791 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1792 | ar.exception.getClass().getName(), |
| 1793 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1794 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1795 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1796 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1797 | } else { |
| 1798 | // use the result as returned |
| 1799 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1800 | } |
| 1801 | } catch (RemoteException re) { |
| 1802 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1803 | } |
| 1804 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1805 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1806 | request = (MainThreadRequest) msg.obj; |
| 1807 | WorkSource ws = (WorkSource) request.argument; |
| 1808 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1809 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1810 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1811 | } |
| 1812 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1813 | ar = (AsyncResult) msg.obj; |
| 1814 | request = (MainThreadRequest) ar.userObj; |
| 1815 | if (ar.exception == null) { |
| 1816 | request.result = ar.result; |
| 1817 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1818 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1819 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1820 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | synchronized (request) { |
| 1824 | request.notifyAll(); |
| 1825 | } |
| 1826 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1827 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1828 | case CMD_MODEM_REBOOT: |
| 1829 | request = (MainThreadRequest) msg.obj; |
| 1830 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1831 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1832 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1833 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1834 | handleNullReturnEvent(msg, "rebootModem"); |
| 1835 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1836 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1837 | request = (MainThreadRequest) msg.obj; |
| 1838 | boolean enable = (boolean) request.argument; |
| 1839 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1840 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1841 | PhoneConfigurationManager.getInstance() |
| 1842 | .enablePhone(request.phone, enable, onCompleted); |
| 1843 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1844 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1845 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1846 | ar = (AsyncResult) msg.obj; |
| 1847 | request = (MainThreadRequest) ar.userObj; |
| 1848 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1849 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1850 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1851 | if ((boolean) request.result) { |
| 1852 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1853 | updateModemStateMetrics(); |
| 1854 | } else { |
| 1855 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1856 | + ar.exception); |
| 1857 | } |
| 1858 | notifyRequester(request); |
| 1859 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1860 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1861 | case CMD_GET_MODEM_STATUS: |
| 1862 | request = (MainThreadRequest) msg.obj; |
| 1863 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1864 | PhoneConfigurationManager.getInstance() |
| 1865 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1866 | break; |
| 1867 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1868 | ar = (AsyncResult) msg.obj; |
| 1869 | request = (MainThreadRequest) ar.userObj; |
| 1870 | int id = request.phone.getPhoneId(); |
| 1871 | if (ar.exception == null && ar.result != null) { |
| 1872 | request.result = ar.result; |
| 1873 | //update the cache as modem status has changed |
| 1874 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1875 | (boolean) request.result); |
| 1876 | } else { |
| 1877 | // Return true if modem status cannot be retrieved. For most cases, |
| 1878 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1879 | // and disable modem are not supported. Modem is always on. |
| 1880 | // TODO: this should be fixed in R to support a third |
| 1881 | // status UNKNOWN b/131631629 |
| 1882 | request.result = true; |
| 1883 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1884 | + ar.exception); |
| 1885 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1886 | notifyRequester(request); |
| 1887 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1888 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1889 | request = (MainThreadRequest) msg.obj; |
| 1890 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1891 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1892 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1893 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1894 | break; |
| 1895 | } |
| 1896 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1897 | ar = (AsyncResult) msg.obj; |
| 1898 | request = (MainThreadRequest) ar.userObj; |
| 1899 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1900 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1901 | args.second.accept(ar.exception == null); |
| 1902 | notifyRequester(request); |
| 1903 | break; |
| 1904 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1905 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1906 | request = (MainThreadRequest) msg.obj; |
| 1907 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1908 | Phone phone = getPhoneFromRequest(request); |
| 1909 | if (phone != null) { |
| 1910 | phone.getSystemSelectionChannels(onCompleted); |
| 1911 | } else { |
| 1912 | loge("getSystemSelectionChannels: No phone object"); |
| 1913 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1914 | notifyRequester(request); |
| 1915 | } |
| 1916 | break; |
| 1917 | } |
| 1918 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1919 | ar = (AsyncResult) msg.obj; |
| 1920 | request = (MainThreadRequest) ar.userObj; |
| 1921 | if (ar.exception == null && ar.result != null) { |
| 1922 | request.result = ar.result; |
| 1923 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1924 | request.result = new IllegalStateException( |
| 1925 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1926 | if (ar.result == null) { |
| 1927 | loge("getSystemSelectionChannels: Empty response"); |
| 1928 | } else { |
| 1929 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1930 | } |
| 1931 | } |
| 1932 | notifyRequester(request); |
| 1933 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1934 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1935 | ar = (AsyncResult) msg.obj; |
| 1936 | request = (MainThreadRequest) ar.userObj; |
| 1937 | if (ar.exception == null && ar.result != null) { |
| 1938 | request.result = ar.result; |
| 1939 | } else { |
| 1940 | request.result = -1; |
| 1941 | loge("Failed to set Forbidden Plmns"); |
| 1942 | if (ar.result == null) { |
| 1943 | loge("setForbidenPlmns: Empty response"); |
| 1944 | } else if (ar.exception != null) { |
| 1945 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1946 | request.result = -1; |
| 1947 | } else { |
| 1948 | loge("setForbiddenPlmns: Unknown exception"); |
| 1949 | } |
| 1950 | } |
| 1951 | notifyRequester(request); |
| 1952 | break; |
| 1953 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1954 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1955 | uiccPort = getUiccPortFromRequest(request); |
| 1956 | if (uiccPort == null) { |
| 1957 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1958 | request.result = -1; |
| 1959 | notifyRequester(request); |
| 1960 | break; |
| 1961 | } |
| 1962 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1963 | (Pair<Integer, List<String>>) request.argument; |
| 1964 | appType = setFplmnsArgs.first; |
| 1965 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1966 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1967 | if (uiccApp == null) { |
| 1968 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1969 | request.result = -1; |
| 1970 | loge("Failed to get UICC App"); |
| 1971 | notifyRequester(request); |
| 1972 | } else { |
| 1973 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1974 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1975 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1976 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1977 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1978 | case CMD_ERASE_MODEM_CONFIG: |
| 1979 | request = (MainThreadRequest) msg.obj; |
| 1980 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1981 | defaultPhone.eraseModemConfig(onCompleted); |
| 1982 | break; |
| 1983 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1984 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1985 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1986 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1987 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1988 | request = (MainThreadRequest) msg.obj; |
| 1989 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1990 | notifyRequester(request); |
| 1991 | break; |
| 1992 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1993 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1994 | request = (MainThreadRequest) msg.obj; |
| 1995 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1996 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1997 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1998 | changed.first, changed.second, onCompleted); |
| 1999 | break; |
| 2000 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2001 | ar = (AsyncResult) msg.obj; |
| 2002 | request = (MainThreadRequest) ar.userObj; |
| 2003 | if (ar.exception == null) { |
| 2004 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2005 | // If the operation is successful, update the PIN storage |
| 2006 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2007 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2008 | UiccController.getInstance().getPinStorage() |
| 2009 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2010 | } else { |
| 2011 | request.result = msg.arg1; |
| 2012 | } |
| 2013 | notifyRequester(request); |
| 2014 | break; |
| 2015 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2016 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2017 | request = (MainThreadRequest) msg.obj; |
| 2018 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2019 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2020 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2021 | enabled.first, enabled.second, onCompleted); |
| 2022 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2023 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2024 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2025 | ar = (AsyncResult) msg.obj; |
| 2026 | request = (MainThreadRequest) ar.userObj; |
| 2027 | if (ar.exception == null) { |
| 2028 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2029 | // If the operation is successful, update the PIN storage |
| 2030 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2031 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2032 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2033 | UiccController.getInstance().getPinStorage() |
| 2034 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2035 | } else { |
| 2036 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2037 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2038 | } else { |
| 2039 | request.result = msg.arg1; |
| 2040 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2041 | |
| 2042 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2043 | notifyRequester(request); |
| 2044 | break; |
| 2045 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2046 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2047 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2048 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2049 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2050 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2051 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2052 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2053 | |
| 2054 | case CMD_SET_DATA_THROTTLING: { |
| 2055 | request = (MainThreadRequest) msg.obj; |
| 2056 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2057 | DataThrottlingRequest dataThrottlingRequest = |
| 2058 | (DataThrottlingRequest) request.argument; |
| 2059 | Phone phone = getPhoneFromRequest(request); |
| 2060 | if (phone != null) { |
| 2061 | phone.setDataThrottling(onCompleted, |
| 2062 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2063 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2064 | } else { |
| 2065 | loge("setDataThrottling: No phone object"); |
| 2066 | request.result = |
| 2067 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2068 | notifyRequester(request); |
| 2069 | } |
| 2070 | |
| 2071 | break; |
| 2072 | } |
| 2073 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2074 | ar = (AsyncResult) msg.obj; |
| 2075 | request = (MainThreadRequest) ar.userObj; |
| 2076 | |
| 2077 | if (ar.exception == null) { |
| 2078 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2079 | } else if (ar.exception instanceof CommandException) { |
| 2080 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2081 | CommandException.Error error = |
| 2082 | ((CommandException) (ar.exception)).getCommandError(); |
| 2083 | |
| 2084 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2085 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2086 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2087 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2088 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2089 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2090 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2091 | } else { |
| 2092 | request.result = |
| 2093 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2094 | } |
| 2095 | } else { |
| 2096 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2097 | } |
| 2098 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2099 | notifyRequester(request); |
| 2100 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2101 | |
| 2102 | case CMD_SET_SIM_POWER: { |
| 2103 | request = (MainThreadRequest) msg.obj; |
| 2104 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2105 | request = (MainThreadRequest) msg.obj; |
| 2106 | int stateToSet = |
| 2107 | ((Pair<Integer, IIntegerConsumer>) |
| 2108 | request.argument).first; |
| 2109 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2110 | break; |
| 2111 | } |
| 2112 | case EVENT_SET_SIM_POWER_DONE: { |
| 2113 | ar = (AsyncResult) msg.obj; |
| 2114 | request = (MainThreadRequest) ar.userObj; |
| 2115 | IIntegerConsumer callback = |
| 2116 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2117 | if (ar.exception != null) { |
| 2118 | loge("setSimPower exception: " + ar.exception); |
| 2119 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2120 | .RESULT_ERROR_UNKNOWN; |
| 2121 | if (ar.exception instanceof CommandException) { |
| 2122 | CommandException.Error error = |
| 2123 | ((CommandException) (ar.exception)).getCommandError(); |
| 2124 | if (error == CommandException.Error.SIM_ERR) { |
| 2125 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2126 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2127 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2128 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2129 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2130 | } else { |
| 2131 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2132 | } |
| 2133 | } |
| 2134 | try { |
| 2135 | callback.accept(errorCode); |
| 2136 | } catch (RemoteException e) { |
| 2137 | // Ignore if the remote process is no longer available to call back. |
| 2138 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2139 | } |
| 2140 | } else { |
| 2141 | try { |
| 2142 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2143 | } catch (RemoteException e) { |
| 2144 | // Ignore if the remote process is no longer available to call back. |
| 2145 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2146 | } |
| 2147 | } |
| 2148 | break; |
| 2149 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2150 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2151 | request = (MainThreadRequest) msg.obj; |
| 2152 | |
| 2153 | final Phone phone = getPhoneFromRequest(request); |
| 2154 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2155 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2156 | notifyRequester(request); |
| 2157 | break; |
| 2158 | } |
| 2159 | |
| 2160 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2161 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2162 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2163 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2164 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2165 | request.subId, pair.first /*callingUid*/, |
| 2166 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2167 | break; |
| 2168 | } |
| 2169 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2170 | ar = (AsyncResult) msg.obj; |
| 2171 | request = (MainThreadRequest) ar.userObj; |
| 2172 | // request.result will be the exception of ar if present, true otherwise. |
| 2173 | // Be cautious not to leave result null which will wait() forever |
| 2174 | request.result = ar.exception != null ? ar.exception : true; |
| 2175 | notifyRequester(request); |
| 2176 | break; |
| 2177 | } |
| 2178 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2179 | request = (MainThreadRequest) msg.obj; |
| 2180 | |
| 2181 | Phone phone = getPhoneFromRequest(request); |
| 2182 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2183 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2184 | notifyRequester(request); |
| 2185 | break; |
| 2186 | } |
| 2187 | |
| 2188 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2189 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2190 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2191 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2192 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2193 | request.subId, pair.first /*callingUid*/, |
| 2194 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2195 | break; |
| 2196 | } |
| 2197 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2198 | ar = (AsyncResult) msg.obj; |
| 2199 | request = (MainThreadRequest) ar.userObj; |
| 2200 | request.result = ar.exception != null ? ar.exception : true; |
| 2201 | notifyRequester(request); |
| 2202 | break; |
| 2203 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2204 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2205 | case CMD_GET_SLICING_CONFIG: { |
| 2206 | request = (MainThreadRequest) msg.obj; |
| 2207 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2208 | request.phone.getSlicingConfig(onCompleted); |
| 2209 | break; |
| 2210 | } |
| 2211 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2212 | ar = (AsyncResult) msg.obj; |
| 2213 | request = (MainThreadRequest) ar.userObj; |
| 2214 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2215 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2216 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2217 | Bundle bundle = new Bundle(); |
| 2218 | int resultCode = 0; |
| 2219 | if (ar.exception != null) { |
| 2220 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2221 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2222 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2223 | } else if (ar.result == null) { |
| 2224 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2225 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2226 | } else { |
| 2227 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2228 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2229 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2233 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2234 | } |
| 2235 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2236 | result.send(resultCode, bundle); |
| 2237 | notifyRequester(request); |
| 2238 | break; |
| 2239 | } |
| 2240 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2241 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2242 | request = (MainThreadRequest) msg.obj; |
| 2243 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2244 | PurchasePremiumCapabilityArgument arg = |
| 2245 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2246 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2247 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2248 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2249 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2250 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2251 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2252 | ar = (AsyncResult) msg.obj; |
| 2253 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2254 | PurchasePremiumCapabilityArgument arg = |
| 2255 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2256 | try { |
| 2257 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2258 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2259 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2260 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2261 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2262 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2263 | } catch (RemoteException e) { |
| 2264 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2265 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2266 | + " failed: " + e; |
| 2267 | if (DBG) log(logStr); |
| 2268 | AnomalyReporter.reportAnomaly( |
| 2269 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2270 | } |
| 2271 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2272 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2273 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2274 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2275 | request = (MainThreadRequest) msg.obj; |
| 2276 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2277 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2278 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2279 | notifyRequester(request); |
| 2280 | break; |
| 2281 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | default: |
| 2283 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2284 | break; |
| 2285 | } |
| 2286 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2287 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2288 | private void notifyRequester(MainThreadRequest request) { |
| 2289 | synchronized (request) { |
| 2290 | request.notifyAll(); |
| 2291 | } |
| 2292 | } |
| 2293 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2294 | private void handleNullReturnEvent(Message msg, String command) { |
| 2295 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2296 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2297 | if (ar.exception == null) { |
| 2298 | request.result = true; |
| 2299 | } else { |
| 2300 | request.result = false; |
| 2301 | if (ar.exception instanceof CommandException) { |
| 2302 | loge(command + ": CommandException: " + ar.exception); |
| 2303 | } else { |
| 2304 | loge(command + ": Unknown exception"); |
| 2305 | } |
| 2306 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2307 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2308 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | /** |
| 2312 | * Posts the specified command to be executed on the main thread, |
| 2313 | * waits for the request to complete, and returns the result. |
| 2314 | * @see #sendRequestAsync |
| 2315 | */ |
| 2316 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2317 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2318 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | /** |
| 2322 | * Posts the specified command to be executed on the main thread, |
| 2323 | * waits for the request to complete, and returns the result. |
| 2324 | * @see #sendRequestAsync |
| 2325 | */ |
| 2326 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2327 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2328 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | /** |
| 2332 | * Posts the specified command to be executed on the main thread, |
| 2333 | * waits for the request to complete, and returns the result. |
| 2334 | * @see #sendRequestAsync |
| 2335 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2336 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2337 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * Posts the specified command to be executed on the main thread, |
| 2342 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2343 | * if not timeout or null otherwise. |
| 2344 | * @see #sendRequestAsync |
| 2345 | */ |
| 2346 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2347 | long timeoutInMs) { |
| 2348 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | /** |
| 2352 | * Posts the specified command to be executed on the main thread, |
| 2353 | * waits for the request to complete, and returns the result. |
| 2354 | * @see #sendRequestAsync |
| 2355 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2356 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2357 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -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 | */ |
| 2365 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2366 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2367 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2371 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2372 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2373 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2374 | * @see #sendRequestAsync |
| 2375 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2376 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2377 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2379 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2380 | } |
| 2381 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2382 | MainThreadRequest request = null; |
| 2383 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2384 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2385 | } else if (phone != null) { |
| 2386 | request = new MainThreadRequest(argument, phone, workSource); |
| 2387 | } else { |
| 2388 | request = new MainThreadRequest(argument, subId, workSource); |
| 2389 | } |
| 2390 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2391 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2392 | msg.sendToTarget(); |
| 2393 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2394 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2396 | if (timeoutInMs >= 0) { |
| 2397 | // Wait for at least timeoutInMs before returning null request result |
| 2398 | long now = SystemClock.elapsedRealtime(); |
| 2399 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2400 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2401 | try { |
| 2402 | request.wait(deadline - now); |
| 2403 | } catch (InterruptedException e) { |
| 2404 | // Do nothing, go back and check if request is completed or timeout |
| 2405 | } finally { |
| 2406 | now = SystemClock.elapsedRealtime(); |
| 2407 | } |
| 2408 | } |
| 2409 | } else { |
| 2410 | // Wait for the request to complete |
| 2411 | while (request.result == null) { |
| 2412 | try { |
| 2413 | request.wait(); |
| 2414 | } catch (InterruptedException e) { |
| 2415 | // Do nothing, go back and wait until the request is complete |
| 2416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2420 | if (request.result == null) { |
| 2421 | Log.wtf(LOG_TAG, |
| 2422 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2423 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2424 | return request.result; |
| 2425 | } |
| 2426 | |
| 2427 | /** |
| 2428 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2429 | * Posts the specified command to be executed on the main thread, and |
| 2430 | * returns immediately. |
| 2431 | * @see #sendRequest |
| 2432 | */ |
| 2433 | private void sendRequestAsync(int command) { |
| 2434 | mMainThreadHandler.sendEmptyMessage(command); |
| 2435 | } |
| 2436 | |
| 2437 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2438 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2439 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2440 | */ |
| 2441 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2442 | sendRequestAsync(command, argument, null, null); |
| 2443 | } |
| 2444 | |
| 2445 | /** |
| 2446 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2447 | * @see {@link #sendRequest(int,Object)} |
| 2448 | */ |
| 2449 | private void sendRequestAsync( |
| 2450 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2451 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2452 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2453 | msg.sendToTarget(); |
| 2454 | } |
| 2455 | |
| 2456 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2458 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2459 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2460 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2461 | synchronized (PhoneInterfaceManager.class) { |
| 2462 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2463 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | } else { |
| 2465 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2466 | } |
| 2467 | return sInstance; |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2472 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2473 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2474 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2475 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2477 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2478 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2479 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2481 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2482 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2483 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2484 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2485 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2486 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2487 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2488 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2489 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2490 | mVendorApiLevel = SystemProperties.getInt( |
| 2491 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2492 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2493 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2494 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2495 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2496 | |
| 2497 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2498 | // entitlementStatus for satellite service. |
| 2499 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2502 | @VisibleForTesting |
| 2503 | public SharedPreferences getSharedPreferences() { |
| 2504 | return mTelephonySharedPreferences; |
| 2505 | } |
| 2506 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2507 | /** |
| 2508 | * Get the default phone for this device. |
| 2509 | */ |
| 2510 | @VisibleForTesting |
| 2511 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2512 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2513 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2514 | } |
| 2515 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | private void publish() { |
| 2517 | if (DBG) log("publish: " + this); |
| 2518 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2519 | TelephonyFrameworkInitializer |
| 2520 | .getTelephonyServiceManager() |
| 2521 | .getTelephonyServiceRegisterer() |
| 2522 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2525 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2526 | if (request.phone != null) { |
| 2527 | return request.phone; |
| 2528 | } else { |
| 2529 | return getPhoneFromSubId(request.subId); |
| 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | private Phone getPhoneFromSubId(int subId) { |
| 2534 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2535 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2536 | } |
| 2537 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2538 | /** |
| 2539 | * Get phone object associated with a subscription. |
| 2540 | * Return default phone if phone object associated with subscription is null |
| 2541 | * @param subId - subscriptionId |
| 2542 | * @return phone object associated with a subscription or default phone if null. |
| 2543 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2544 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2545 | Phone phone = getPhoneFromSubId(subId); |
| 2546 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2547 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2548 | phone = getDefaultPhone(); |
| 2549 | } |
| 2550 | return phone; |
| 2551 | } |
| 2552 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2553 | @Nullable |
| 2554 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2555 | Phone phone = getPhoneFromRequest(request); |
| 2556 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2557 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2558 | } |
| 2559 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2560 | /** |
| 2561 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2562 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2563 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2564 | * @return The Phone associated the sub Id |
| 2565 | */ |
| 2566 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2567 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2568 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2569 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2570 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2571 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2572 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2573 | } |
| 2574 | |
| 2575 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2576 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2577 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2580 | private boolean isImsAvailableOnDevice() { |
| 2581 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2582 | if (pm == null) { |
| 2583 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2584 | // so do not throw error and allow. |
| 2585 | return true; |
| 2586 | } |
| 2587 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2588 | } |
| 2589 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2590 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2591 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2592 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2593 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2594 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2597 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2598 | if (DBG) log("dial: " + number); |
| 2599 | // No permission check needed here: This is just a wrapper around the |
| 2600 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2601 | // the UI before it does anything. |
| 2602 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2603 | final long identity = Binder.clearCallingIdentity(); |
| 2604 | try { |
| 2605 | String url = createTelUrl(number); |
| 2606 | if (url == null) { |
| 2607 | return; |
| 2608 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2609 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2610 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2611 | PhoneConstants.State state = mCM.getState(subId); |
| 2612 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2613 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2614 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2615 | mApp.startActivity(intent); |
| 2616 | } |
| 2617 | } finally { |
| 2618 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2623 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2626 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2627 | if (DBG) log("call: " + number); |
| 2628 | |
| 2629 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2630 | // need to do a permission check since we're calling startActivity() |
| 2631 | // from the context of the phone app. |
| 2632 | enforceCallPermission(); |
| 2633 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2634 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2635 | != AppOpsManager.MODE_ALLOWED) { |
| 2636 | return; |
| 2637 | } |
| 2638 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2639 | enforceTelephonyFeatureWithException(callingPackage, |
| 2640 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2641 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | final long identity = Binder.clearCallingIdentity(); |
| 2643 | try { |
| 2644 | String url = createTelUrl(number); |
| 2645 | if (url == null) { |
| 2646 | return; |
| 2647 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2648 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | boolean isValid = false; |
| 2650 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2651 | if (slist != null) { |
| 2652 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2653 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2654 | isValid = true; |
| 2655 | break; |
| 2656 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2657 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2658 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | if (!isValid) { |
| 2660 | return; |
| 2661 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2662 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2664 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2665 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2666 | mApp.startActivity(intent); |
| 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(identity); |
| 2669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2672 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2673 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2674 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2675 | } |
| 2676 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2677 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2678 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2679 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2680 | } |
| 2681 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2682 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2685 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2686 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2687 | "supplyPinReportResultForSubscriber"); |
| 2688 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2689 | final long identity = Binder.clearCallingIdentity(); |
| 2690 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2691 | Phone phone = getPhone(subId); |
| 2692 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | checkSimPin.start(); |
| 2694 | return checkSimPin.unlockSim(null, pin); |
| 2695 | } finally { |
| 2696 | Binder.restoreCallingIdentity(identity); |
| 2697 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2700 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2701 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2703 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2704 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2705 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2706 | final long identity = Binder.clearCallingIdentity(); |
| 2707 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2708 | Phone phone = getPhone(subId); |
| 2709 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2710 | checkSimPuk.start(); |
| 2711 | return checkSimPuk.unlockSim(puk, pin); |
| 2712 | } finally { |
| 2713 | Binder.restoreCallingIdentity(identity); |
| 2714 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2718 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2719 | * a synchronous one. |
| 2720 | */ |
| 2721 | private static class UnlockSim extends Thread { |
| 2722 | |
| 2723 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2724 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 | |
| 2726 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2727 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2728 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | |
| 2730 | // For replies from SimCard interface |
| 2731 | private Handler mHandler; |
| 2732 | |
| 2733 | // For async handler to identify request type |
| 2734 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2735 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2736 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2737 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2738 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2739 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2740 | UnlockSim(int phoneId, IccCard simCard) { |
| 2741 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | mSimCard = simCard; |
| 2743 | } |
| 2744 | |
| 2745 | @Override |
| 2746 | public void run() { |
| 2747 | Looper.prepare(); |
| 2748 | synchronized (UnlockSim.this) { |
| 2749 | mHandler = new Handler() { |
| 2750 | @Override |
| 2751 | public void handleMessage(Message msg) { |
| 2752 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2753 | switch (msg.what) { |
| 2754 | case SUPPLY_PIN_COMPLETE: |
| 2755 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2756 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2757 | mRetryCount = msg.arg1; |
| 2758 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2759 | CommandException.Error error = null; |
| 2760 | if (ar.exception instanceof CommandException) { |
| 2761 | error = ((CommandException) (ar.exception)) |
| 2762 | .getCommandError(); |
| 2763 | } |
| 2764 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2765 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2766 | } else if (error == CommandException.Error.ABORTED) { |
| 2767 | /* When UiccCardApp dispose, handle message and return |
| 2768 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2769 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2770 | } else { |
| 2771 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2772 | } |
| 2773 | } else { |
| 2774 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2775 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2776 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2777 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | UnlockSim.this.notifyAll(); |
| 2779 | } |
| 2780 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2781 | case SUPPLY_PIN_DELAYED: |
| 2782 | if(!mDone) { |
| 2783 | String logStr = "Delay in receiving SIM PIN response "; |
| 2784 | if (DBG) log(logStr); |
| 2785 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2786 | } |
| 2787 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2788 | } |
| 2789 | } |
| 2790 | }; |
| 2791 | UnlockSim.this.notifyAll(); |
| 2792 | } |
| 2793 | Looper.loop(); |
| 2794 | } |
| 2795 | |
| 2796 | /* |
| 2797 | * Use PIN or PUK to unlock SIM card |
| 2798 | * |
| 2799 | * If PUK is null, unlock SIM card with PIN |
| 2800 | * |
| 2801 | * 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] | 2802 | * |
| 2803 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2804 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2805 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2806 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2807 | |
| 2808 | while (mHandler == null) { |
| 2809 | try { |
| 2810 | wait(); |
| 2811 | } catch (InterruptedException e) { |
| 2812 | Thread.currentThread().interrupt(); |
| 2813 | } |
| 2814 | } |
| 2815 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2816 | |
| 2817 | if (puk == null) { |
| 2818 | mSimCard.supplyPin(pin, callback); |
| 2819 | } else { |
| 2820 | mSimCard.supplyPuk(puk, pin, callback); |
| 2821 | } |
| 2822 | |
| 2823 | while (!mDone) { |
| 2824 | try { |
| 2825 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2826 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2827 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2828 | wait(); |
| 2829 | } catch (InterruptedException e) { |
| 2830 | // Restore the interrupted status |
| 2831 | Thread.currentThread().interrupt(); |
| 2832 | } |
| 2833 | } |
| 2834 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2835 | int[] resultArray = new int[2]; |
| 2836 | resultArray[0] = mResult; |
| 2837 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2838 | |
| 2839 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2840 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2841 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2842 | // This instance is no longer reused, so quit its thread's looper. |
| 2843 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2844 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2845 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2849 | /** |
| 2850 | * This method has been removed due to privacy and stability concerns. |
| 2851 | */ |
| 2852 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2853 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2854 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2855 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2858 | @Override |
| 2859 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2860 | mApp.getSystemService(AppOpsManager.class) |
| 2861 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2862 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2863 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2864 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2865 | // Callers targeting S have no business invoking this method. |
| 2866 | return; |
| 2867 | } |
| 2868 | |
| 2869 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2870 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2871 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2872 | .setCallingPackage(callingPackage) |
| 2873 | .setCallingFeatureId(null) |
| 2874 | .setCallingPid(Binder.getCallingPid()) |
| 2875 | .setCallingUid(Binder.getCallingUid()) |
| 2876 | .setMethod("updateServiceLocation") |
| 2877 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2878 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2879 | .build()); |
| 2880 | // Apps that lack location permission have no business calling this method; |
| 2881 | // however, because no permission was declared in the public API, denials must |
| 2882 | // all be "soft". |
| 2883 | switch (locationResult) { |
| 2884 | case DENIED_HARD: /* fall through */ |
| 2885 | case DENIED_SOFT: |
| 2886 | return; |
| 2887 | } |
| 2888 | |
| 2889 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2890 | final long identity = Binder.clearCallingIdentity(); |
| 2891 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2892 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2893 | } finally { |
| 2894 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2895 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2898 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2899 | @Override |
| 2900 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2901 | return isRadioOnWithFeature(callingPackage, null); |
| 2902 | } |
| 2903 | |
| 2904 | |
| 2905 | @Override |
| 2906 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2907 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2908 | callingFeatureId); |
| 2909 | } |
| 2910 | |
| 2911 | @Deprecated |
| 2912 | @Override |
| 2913 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2914 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2915 | } |
| 2916 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2917 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2918 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2919 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2920 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2921 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2922 | return false; |
| 2923 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2925 | enforceTelephonyFeatureWithException(callingPackage, |
| 2926 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2927 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2928 | final long identity = Binder.clearCallingIdentity(); |
| 2929 | try { |
| 2930 | return isRadioOnForSubscriber(subId); |
| 2931 | } finally { |
| 2932 | Binder.restoreCallingIdentity(identity); |
| 2933 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2937 | final long identity = Binder.clearCallingIdentity(); |
| 2938 | try { |
| 2939 | final Phone phone = getPhone(subId); |
| 2940 | if (phone != null) { |
| 2941 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2942 | } else { |
| 2943 | return false; |
| 2944 | } |
| 2945 | } finally { |
| 2946 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2947 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2951 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2952 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2953 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2954 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2955 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2957 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2958 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2959 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2960 | final long identity = Binder.clearCallingIdentity(); |
| 2961 | try { |
| 2962 | final Phone phone = getPhone(subId); |
| 2963 | if (phone != null) { |
| 2964 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2965 | } |
| 2966 | } finally { |
| 2967 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2968 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2972 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2975 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2976 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2977 | |
| 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
| 2980 | final Phone phone = getPhone(subId); |
| 2981 | if (phone == null) { |
| 2982 | return false; |
| 2983 | } |
| 2984 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2985 | toggleRadioOnOffForSubscriber(subId); |
| 2986 | } |
| 2987 | return true; |
| 2988 | } finally { |
| 2989 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2990 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2991 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2992 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2993 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2994 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2995 | |
| 2996 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2997 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2998 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2999 | /* |
| 3000 | * If any of the Radios are available, it will need to be |
| 3001 | * shutdown. So return true if any Radio is available. |
| 3002 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | try { |
| 3005 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3006 | Phone phone = PhoneFactory.getPhone(i); |
| 3007 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3008 | } |
| 3009 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3010 | return false; |
| 3011 | } finally { |
| 3012 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3013 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3016 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3017 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3018 | enforceModifyPermission(); |
| 3019 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3020 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3021 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3022 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | final long identity = Binder.clearCallingIdentity(); |
| 3024 | try { |
| 3025 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3026 | logv("Shutting down Phone " + i); |
| 3027 | shutdownRadioUsingPhoneId(i); |
| 3028 | } |
| 3029 | } finally { |
| 3030 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3031 | } |
| 3032 | } |
| 3033 | |
| 3034 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3035 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3036 | if (phone != null && phone.isRadioAvailable()) { |
| 3037 | phone.shutdownRadio(); |
| 3038 | } |
| 3039 | } |
| 3040 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3041 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3042 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3043 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3044 | if (!turnOn) { |
| 3045 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3046 | } |
| 3047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3048 | final long identity = Binder.clearCallingIdentity(); |
| 3049 | try { |
| 3050 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3051 | if (defaultPhone != null) { |
| 3052 | defaultPhone.setRadioPower(turnOn); |
| 3053 | return true; |
| 3054 | } else { |
| 3055 | loge("There's no default phone."); |
| 3056 | return false; |
| 3057 | } |
| 3058 | } finally { |
| 3059 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3060 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3063 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3064 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3065 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3066 | if (!turnOn) { |
| 3067 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3068 | + ",callingPackage=" + getCurrentPackageName()); |
| 3069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | final Phone phone = getPhone(subId); |
| 3073 | if (phone != null) { |
| 3074 | phone.setRadioPower(turnOn); |
| 3075 | return true; |
| 3076 | } else { |
| 3077 | return false; |
| 3078 | } |
| 3079 | } finally { |
| 3080 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3081 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3084 | /** |
| 3085 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3086 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3087 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3088 | * powering it off, and these radio off votes will be cleared. |
| 3089 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3090 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3091 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3092 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3093 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3094 | * check its vote. |
| 3095 | * |
| 3096 | * @param subId The subscription ID. |
| 3097 | * @param reason The reason for powering off radio. |
| 3098 | * @return true on success and false on failure. |
| 3099 | */ |
| 3100 | public boolean requestRadioPowerOffForReason(int subId, |
| 3101 | @TelephonyManager.RadioPowerReason int reason) { |
| 3102 | enforceModifyPermission(); |
| 3103 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3104 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3105 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3106 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3107 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3108 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3109 | final long identity = Binder.clearCallingIdentity(); |
| 3110 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3111 | boolean result = false; |
| 3112 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3113 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3114 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3115 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3116 | if (!result) { |
| 3117 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3118 | } |
| 3119 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
| 3122 | } |
| 3123 | } |
| 3124 | |
| 3125 | /** |
| 3126 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3127 | * {@link requestRadioPowerOffForReason}. |
| 3128 | * |
| 3129 | * @param subId The subscription ID. |
| 3130 | * @param reason The reason for powering off radio. |
| 3131 | * @return true on success and false on failure. |
| 3132 | */ |
| 3133 | public boolean clearRadioPowerOffForReason(int subId, |
| 3134 | @TelephonyManager.RadioPowerReason int reason) { |
| 3135 | enforceModifyPermission(); |
| 3136 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3137 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3138 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3139 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3140 | final long identity = Binder.clearCallingIdentity(); |
| 3141 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3142 | boolean result = false; |
| 3143 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3144 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3145 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3146 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3147 | if (!result) { |
| 3148 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3149 | } |
| 3150 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3151 | } finally { |
| 3152 | Binder.restoreCallingIdentity(identity); |
| 3153 | } |
| 3154 | } |
| 3155 | |
| 3156 | /** |
| 3157 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3158 | * |
| 3159 | * @param subId The subscription ID. |
| 3160 | * @param callingPackage The package making the call. |
| 3161 | * @param callingFeatureId The feature in the package. |
| 3162 | * @return List of reasons for powering off radio. |
| 3163 | */ |
| 3164 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3165 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3166 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3167 | enforceTelephonyFeatureWithException(callingPackage, |
| 3168 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3169 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3170 | final long identity = Binder.clearCallingIdentity(); |
| 3171 | List result = new ArrayList(); |
| 3172 | try { |
| 3173 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3174 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3175 | return result; |
| 3176 | } |
| 3177 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3178 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3179 | if (phone != null) { |
| 3180 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3181 | } else { |
| 3182 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3183 | } |
| 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
| 3186 | } |
| 3187 | return result; |
| 3188 | } |
| 3189 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3190 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3191 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3192 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3193 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3195 | enforceTelephonyFeatureWithException(callingPackage, |
| 3196 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3197 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3198 | final long identity = Binder.clearCallingIdentity(); |
| 3199 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3200 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3202 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3203 | phone.getDataSettingsManager().setDataEnabled( |
| 3204 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | return true; |
| 3206 | } else { |
| 3207 | return false; |
| 3208 | } |
| 3209 | } finally { |
| 3210 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3211 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3212 | } |
| 3213 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3214 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3215 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3216 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3217 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3218 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3219 | enforceTelephonyFeatureWithException(callingPackage, |
| 3220 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3224 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3225 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3226 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3227 | phone.getDataSettingsManager().setDataEnabled( |
| 3228 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | return true; |
| 3230 | } else { |
| 3231 | return false; |
| 3232 | } |
| 3233 | } finally { |
| 3234 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3235 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3238 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3239 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3240 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3241 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3242 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3243 | final long identity = Binder.clearCallingIdentity(); |
| 3244 | try { |
| 3245 | final Phone phone = getPhone(subId); |
| 3246 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3247 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | } else { |
| 3249 | return false; |
| 3250 | } |
| 3251 | } finally { |
| 3252 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3253 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3257 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3260 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3261 | enforceCallPermission(); |
| 3262 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3263 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3264 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3265 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3266 | final long identity = Binder.clearCallingIdentity(); |
| 3267 | try { |
| 3268 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3269 | return; |
| 3270 | } |
| 3271 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3272 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3273 | } finally { |
| 3274 | Binder.restoreCallingIdentity(identity); |
| 3275 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3276 | }; |
| 3277 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3278 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3279 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3280 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3281 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3282 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3283 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | final long identity = Binder.clearCallingIdentity(); |
| 3285 | try { |
| 3286 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3287 | return false; |
| 3288 | } |
| 3289 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3290 | } finally { |
| 3291 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3292 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3295 | /** |
| 3296 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3297 | * tag on getCallState Binder call. |
| 3298 | */ |
| 3299 | @Deprecated |
| 3300 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3301 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3302 | if (CompatChanges.isChangeEnabled( |
| 3303 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3304 | Binder.getCallingUid())) { |
| 3305 | // Do not allow this API to be called on API version 31+, it should only be |
| 3306 | // called on old apps using this Binder call directly. |
| 3307 | throw new SecurityException("This method can only be used for applications " |
| 3308 | + "targeting API version 30 or less."); |
| 3309 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3310 | final long identity = Binder.clearCallingIdentity(); |
| 3311 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3312 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3313 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3314 | } finally { |
| 3315 | Binder.restoreCallingIdentity(identity); |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | @Override |
| 3320 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3321 | if (CompatChanges.isChangeEnabled( |
| 3322 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3323 | Binder.getCallingUid())) { |
| 3324 | // Check READ_PHONE_STATE for API version 31+ |
| 3325 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3326 | featureId, "getCallStateForSubscription")) { |
| 3327 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3328 | + "targeting API level 31+."); |
| 3329 | } |
| 3330 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3331 | |
| 3332 | enforceTelephonyFeatureWithException(callingPackage, |
| 3333 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3334 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3335 | final long identity = Binder.clearCallingIdentity(); |
| 3336 | try { |
| 3337 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3339 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(identity); |
| 3342 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3345 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3346 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3347 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | @Override |
| 3351 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3352 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3353 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3354 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | final long identity = Binder.clearCallingIdentity(); |
| 3356 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3357 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3359 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3360 | } else { |
| 3361 | return PhoneConstantConversions.convertDataState( |
| 3362 | PhoneConstants.DataState.DISCONNECTED); |
| 3363 | } |
| 3364 | } finally { |
| 3365 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3366 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3367 | } |
| 3368 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3369 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3370 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3371 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3375 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3376 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3377 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3379 | final long identity = Binder.clearCallingIdentity(); |
| 3380 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3381 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3382 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3383 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3384 | } else { |
| 3385 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3386 | } |
| 3387 | } finally { |
| 3388 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3389 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3393 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3394 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3395 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3396 | |
| 3397 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3398 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3399 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3400 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3401 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3402 | .setCallingPid(Binder.getCallingPid()) |
| 3403 | .setCallingUid(Binder.getCallingUid()) |
| 3404 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3405 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3406 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3407 | .build()); |
| 3408 | switch (locationResult) { |
| 3409 | case DENIED_HARD: |
| 3410 | throw new SecurityException("Not allowed to access cell location"); |
| 3411 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3412 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3413 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3416 | enforceTelephonyFeatureWithException(callingPackage, |
| 3417 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3418 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3419 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | final long identity = Binder.clearCallingIdentity(); |
| 3421 | try { |
| 3422 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3423 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3424 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3425 | } finally { |
| 3426 | Binder.restoreCallingIdentity(identity); |
| 3427 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3430 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3431 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3432 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3433 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3434 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3435 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3436 | // registered cell info, so return a NULL country instead. |
| 3437 | final long identity = Binder.clearCallingIdentity(); |
| 3438 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3439 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3440 | // Get default phone in this case. |
| 3441 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3442 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3443 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3444 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3445 | if (phone == null) return ""; |
| 3446 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3447 | if (sst == null) return ""; |
| 3448 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3449 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3450 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3451 | } finally { |
| 3452 | Binder.restoreCallingIdentity(identity); |
| 3453 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3456 | /** |
| 3457 | * This method was removed due to potential issues caused by performing partial |
| 3458 | * updates of service state, and lack of a credible use case. |
| 3459 | * |
| 3460 | * This has the ability to break the telephony implementation by disabling notification of |
| 3461 | * changes in device connectivity. DO NOT USE THIS! |
| 3462 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3463 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3464 | public void enableLocationUpdates() { |
| 3465 | mApp.enforceCallingOrSelfPermission( |
| 3466 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3469 | /** |
| 3470 | * This method was removed due to potential issues caused by performing partial |
| 3471 | * updates of service state, and lack of a credible use case. |
| 3472 | * |
| 3473 | * This has the ability to break the telephony implementation by disabling notification of |
| 3474 | * changes in device connectivity. DO NOT USE THIS! |
| 3475 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3476 | @Override |
| 3477 | public void disableLocationUpdates() { |
| 3478 | mApp.enforceCallingOrSelfPermission( |
| 3479 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | @Override |
| 3483 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3484 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3485 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3486 | try { |
| 3487 | mApp.getSystemService(AppOpsManager.class) |
| 3488 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3489 | } catch (SecurityException e) { |
| 3490 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3491 | throw e; |
| 3492 | } |
| 3493 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3494 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3495 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3496 | throw new SecurityException( |
| 3497 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3498 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3499 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3500 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3501 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3502 | return null; |
| 3503 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3504 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3505 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3506 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3507 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3508 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3509 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3510 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3511 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3512 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3513 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3514 | for (CellInfo ci : info) { |
| 3515 | if (ci instanceof CellInfoGsm) { |
| 3516 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3517 | } else if (ci instanceof CellInfoWcdma) { |
| 3518 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3520 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3521 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3524 | private List<CellInfo> getCachedCellInfo() { |
| 3525 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3526 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3527 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3528 | if (info != null) cellInfos.addAll(info); |
| 3529 | } |
| 3530 | return cellInfos; |
| 3531 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3532 | |
| 3533 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3534 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3535 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3536 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3537 | |
| 3538 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3539 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3540 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3541 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3542 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3543 | .setCallingPid(Binder.getCallingPid()) |
| 3544 | .setCallingUid(Binder.getCallingUid()) |
| 3545 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3546 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3547 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3548 | .build()); |
| 3549 | switch (locationResult) { |
| 3550 | case DENIED_HARD: |
| 3551 | throw new SecurityException("Not allowed to access cell info"); |
| 3552 | case DENIED_SOFT: |
| 3553 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3556 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3557 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3558 | return getCachedCellInfo(); |
| 3559 | } |
| 3560 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3561 | enforceTelephonyFeatureWithException(callingPackage, |
| 3562 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3563 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3564 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3565 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3566 | final long identity = Binder.clearCallingIdentity(); |
| 3567 | try { |
| 3568 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3569 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3570 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3571 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3572 | if (info != null) cellInfos.addAll(info); |
| 3573 | } |
| 3574 | return cellInfos; |
| 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3580 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3581 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3582 | String callingFeatureId) { |
| 3583 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3584 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3588 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3589 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3590 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3591 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3594 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3595 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3596 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3597 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3598 | |
| 3599 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3600 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3601 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3602 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3603 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3604 | .setCallingPid(Binder.getCallingPid()) |
| 3605 | .setCallingUid(Binder.getCallingUid()) |
| 3606 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3607 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3608 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3609 | .build()); |
| 3610 | switch (locationResult) { |
| 3611 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3612 | if (TelephonyPermissions |
| 3613 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3614 | // Safetynet logging for b/154934934 |
| 3615 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3616 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3617 | throw new SecurityException("Not allowed to access cell info"); |
| 3618 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3619 | if (TelephonyPermissions |
| 3620 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3621 | // Safetynet logging for b/154934934 |
| 3622 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3623 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3624 | try { |
| 3625 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3626 | } catch (RemoteException re) { |
| 3627 | // Drop without consequences |
| 3628 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3629 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3630 | } |
| 3631 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3632 | enforceTelephonyFeatureWithException(callingPackage, |
| 3633 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3634 | |
| 3635 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3636 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3637 | |
| 3638 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3639 | } |
| 3640 | |
| 3641 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3642 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3643 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3644 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3645 | |
| 3646 | final long identity = Binder.clearCallingIdentity(); |
| 3647 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3648 | Phone phone = getPhone(subId); |
| 3649 | if (phone == null) { |
| 3650 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3651 | } else { |
| 3652 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3653 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | } finally { |
| 3655 | Binder.restoreCallingIdentity(identity); |
| 3656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3659 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3660 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3661 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3662 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3663 | return null; |
| 3664 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3665 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3666 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3667 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3668 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3669 | return null; |
| 3670 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3671 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3672 | enforceTelephonyFeatureWithException(callingPackage, |
| 3673 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3674 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3675 | final long identity = Binder.clearCallingIdentity(); |
| 3676 | try { |
| 3677 | return phone.getImei(); |
| 3678 | } finally { |
| 3679 | Binder.restoreCallingIdentity(identity); |
| 3680 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3684 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3685 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3686 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3687 | callingFeatureId, "getPrimaryImei")) { |
| 3688 | throw new SecurityException("Caller does not have permission"); |
| 3689 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3690 | |
| 3691 | enforceTelephonyFeatureWithException(callingPackage, |
| 3692 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3693 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3694 | final long identity = Binder.clearCallingIdentity(); |
| 3695 | try { |
| 3696 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3697 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3698 | return phone.getImei(); |
| 3699 | } |
| 3700 | } |
| 3701 | throw new UnsupportedOperationException("Operation not supported"); |
| 3702 | } finally { |
| 3703 | Binder.restoreCallingIdentity(identity); |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3708 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3709 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3710 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3711 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3712 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3713 | String tac = null; |
| 3714 | if (phone != null) { |
| 3715 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3716 | try { |
| 3717 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3718 | } catch (IndexOutOfBoundsException e) { |
| 3719 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3720 | return null; |
| 3721 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3722 | } |
| 3723 | return tac; |
| 3724 | } |
| 3725 | |
| 3726 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3727 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3728 | try { |
| 3729 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3730 | } catch (SecurityException se) { |
| 3731 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3732 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3733 | + Binder.getCallingUid()); |
| 3734 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3735 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3736 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3737 | return null; |
| 3738 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3739 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3740 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3741 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3742 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3743 | return null; |
| 3744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3745 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3746 | enforceTelephonyFeatureWithException(callingPackage, |
| 3747 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3748 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3749 | final long identity = Binder.clearCallingIdentity(); |
| 3750 | try { |
| 3751 | return phone.getMeid(); |
| 3752 | } finally { |
| 3753 | Binder.restoreCallingIdentity(identity); |
| 3754 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3758 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3759 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3760 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3761 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3762 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3763 | String manufacturerCode = null; |
| 3764 | if (phone != null) { |
| 3765 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3766 | try { |
| 3767 | manufacturerCode = |
| 3768 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3769 | } catch (IndexOutOfBoundsException e) { |
| 3770 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3771 | return null; |
| 3772 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3773 | } |
| 3774 | return manufacturerCode; |
| 3775 | } |
| 3776 | |
| 3777 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3778 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3779 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3780 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3781 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3782 | return null; |
| 3783 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3784 | int subId = phone.getSubId(); |
| 3785 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3786 | mApp, subId, callingPackage, callingFeatureId, |
| 3787 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3788 | return null; |
| 3789 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3790 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3791 | enforceTelephonyFeatureWithException(callingPackage, |
| 3792 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3793 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | final long identity = Binder.clearCallingIdentity(); |
| 3795 | try { |
| 3796 | return phone.getDeviceSvn(); |
| 3797 | } finally { |
| 3798 | Binder.restoreCallingIdentity(identity); |
| 3799 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3802 | @Override |
| 3803 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3804 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3805 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3806 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3807 | final long identity = Binder.clearCallingIdentity(); |
| 3808 | try { |
| 3809 | final Phone phone = getPhone(subId); |
| 3810 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3811 | } finally { |
| 3812 | Binder.restoreCallingIdentity(identity); |
| 3813 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | @Override |
| 3817 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3818 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3819 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3820 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3821 | final long identity = Binder.clearCallingIdentity(); |
| 3822 | try { |
| 3823 | final Phone phone = getPhone(subId); |
| 3824 | return phone == null ? null : phone.getCarrierName(); |
| 3825 | } finally { |
| 3826 | Binder.restoreCallingIdentity(identity); |
| 3827 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3828 | } |
| 3829 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3830 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3831 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3832 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3833 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3834 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3835 | final long identity = Binder.clearCallingIdentity(); |
| 3836 | try { |
| 3837 | final Phone phone = getPhone(subId); |
| 3838 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3839 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
| 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3846 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3847 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3848 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3849 | "getSubscriptionSpecificCarrierName"); |
| 3850 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3851 | final long identity = Binder.clearCallingIdentity(); |
| 3852 | try { |
| 3853 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3854 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3855 | } finally { |
| 3856 | Binder.restoreCallingIdentity(identity); |
| 3857 | } |
| 3858 | } |
| 3859 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3860 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3861 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3862 | if (!isSubscriptionMccMnc) { |
| 3863 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3864 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3865 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3866 | if (phone == null) { |
| 3867 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3868 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3869 | |
| 3870 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3871 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3872 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3873 | final long identity = Binder.clearCallingIdentity(); |
| 3874 | try { |
| 3875 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(identity); |
| 3878 | } |
| 3879 | } |
| 3880 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3881 | // |
| 3882 | // Internal helper methods. |
| 3883 | // |
| 3884 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3885 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3886 | * Make sure the caller is the calling package itself |
| 3887 | * |
| 3888 | * @throws SecurityException if the caller is not the calling package |
| 3889 | */ |
| 3890 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3891 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3892 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3893 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3894 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3895 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3896 | } catch (PackageManager.NameNotFoundException e) { |
| 3897 | // packageUid is -1 |
| 3898 | } |
| 3899 | if (packageUid != callingUid) { |
| 3900 | throw new SecurityException(message + ": Package " + callingPackage |
| 3901 | + " does not belong to " + callingUid); |
| 3902 | } |
| 3903 | } |
| 3904 | |
| 3905 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3906 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3907 | * |
| 3908 | * @throws SecurityException if the caller does not have the required permission |
| 3909 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3910 | @VisibleForTesting |
| 3911 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3912 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3913 | } |
| 3914 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3915 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3916 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3917 | * |
| 3918 | * @throws SecurityException if the caller does not have the required permission |
| 3919 | */ |
| 3920 | @VisibleForTesting |
| 3921 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3922 | enforceReadPermission(null); |
| 3923 | } |
| 3924 | |
| 3925 | /** |
| 3926 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3927 | * |
| 3928 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3929 | */ |
| 3930 | @VisibleForTesting |
| 3931 | public void enforceReadPermission(String msg) { |
| 3932 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3933 | } |
| 3934 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3935 | private void enforceActiveEmergencySessionPermission() { |
| 3936 | mApp.enforceCallingOrSelfPermission( |
| 3937 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3938 | } |
| 3939 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3940 | /** |
| 3941 | * Make sure the caller has the CALL_PHONE permission. |
| 3942 | * |
| 3943 | * @throws SecurityException if the caller does not have the required permission |
| 3944 | */ |
| 3945 | private void enforceCallPermission() { |
| 3946 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3947 | } |
| 3948 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3949 | private void enforceSettingsPermission() { |
| 3950 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3953 | private void enforceRebootPermission() { |
| 3954 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3955 | } |
| 3956 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3957 | /** |
| 3958 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3959 | * @param message - log message to print. |
| 3960 | * @throws SecurityException if the caller does not have the required permission |
| 3961 | */ |
| 3962 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3963 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3964 | } |
| 3965 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3966 | /** |
| 3967 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3968 | * @param message - log message to print. |
| 3969 | * @throws SecurityException if the caller does not have the required permission |
| 3970 | */ |
| 3971 | private void enforcePackageUsageStatsPermission(String message) { |
| 3972 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3973 | } |
| 3974 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3975 | private String createTelUrl(String number) { |
| 3976 | if (TextUtils.isEmpty(number)) { |
| 3977 | return null; |
| 3978 | } |
| 3979 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3980 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3983 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3984 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3987 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3988 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3989 | } |
| 3990 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3991 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3992 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3995 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3996 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3997 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4000 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4001 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4002 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4003 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4004 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4005 | final long identity = Binder.clearCallingIdentity(); |
| 4006 | try { |
| 4007 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4008 | if (phone == null) { |
| 4009 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4010 | } else { |
| 4011 | return phone.getPhoneType(); |
| 4012 | } |
| 4013 | } finally { |
| 4014 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | /** |
| 4019 | * Returns the CDMA ERI icon index to display |
| 4020 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4021 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4022 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4023 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4024 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4027 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4028 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4029 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4030 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4031 | mApp, subId, callingPackage, callingFeatureId, |
| 4032 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4033 | return -1; |
| 4034 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4035 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4036 | enforceTelephonyFeatureWithException(callingPackage, |
| 4037 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4038 | "getCdmaEriIconIndexForSubscriber"); |
| 4039 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4040 | final long identity = Binder.clearCallingIdentity(); |
| 4041 | try { |
| 4042 | final Phone phone = getPhone(subId); |
| 4043 | if (phone != null) { |
| 4044 | return phone.getCdmaEriIconIndex(); |
| 4045 | } else { |
| 4046 | return -1; |
| 4047 | } |
| 4048 | } finally { |
| 4049 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4050 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | /** |
| 4054 | * Returns the CDMA ERI icon mode, |
| 4055 | * 0 - ON |
| 4056 | * 1 - FLASHING |
| 4057 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4058 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4059 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4060 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4061 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4064 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4065 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4066 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4068 | mApp, subId, callingPackage, callingFeatureId, |
| 4069 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4070 | return -1; |
| 4071 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4072 | |
| 4073 | final long identity = Binder.clearCallingIdentity(); |
| 4074 | try { |
| 4075 | final Phone phone = getPhone(subId); |
| 4076 | if (phone != null) { |
| 4077 | return phone.getCdmaEriIconMode(); |
| 4078 | } else { |
| 4079 | return -1; |
| 4080 | } |
| 4081 | } finally { |
| 4082 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4083 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | /** |
| 4087 | * Returns the CDMA ERI text, |
| 4088 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4089 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4090 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4091 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4092 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4095 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4096 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4097 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4098 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4099 | mApp, subId, callingPackage, callingFeatureId, |
| 4100 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4101 | return null; |
| 4102 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4103 | |
| 4104 | final long identity = Binder.clearCallingIdentity(); |
| 4105 | try { |
| 4106 | final Phone phone = getPhone(subId); |
| 4107 | if (phone != null) { |
| 4108 | return phone.getCdmaEriText(); |
| 4109 | } else { |
| 4110 | return null; |
| 4111 | } |
| 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4115 | } |
| 4116 | |
| 4117 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4118 | * Returns the CDMA MDN. |
| 4119 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4120 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4121 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4123 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4124 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4125 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4126 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4127 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4128 | final long identity = Binder.clearCallingIdentity(); |
| 4129 | try { |
| 4130 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4131 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | return phone.getLine1Number(); |
| 4133 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4134 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4135 | return null; |
| 4136 | } |
| 4137 | } finally { |
| 4138 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | /** |
| 4143 | * Returns the CDMA MIN. |
| 4144 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4145 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4146 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4148 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4149 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4150 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4151 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4152 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4153 | final long identity = Binder.clearCallingIdentity(); |
| 4154 | try { |
| 4155 | final Phone phone = getPhone(subId); |
| 4156 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4157 | return phone.getCdmaMin(); |
| 4158 | } else { |
| 4159 | return null; |
| 4160 | } |
| 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4166 | @Override |
| 4167 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4168 | INumberVerificationCallback callback, String callingPackage) { |
| 4169 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4170 | != PERMISSION_GRANTED) { |
| 4171 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4172 | } |
| 4173 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4174 | |
| 4175 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4176 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4177 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4178 | + "calling package: " + callingPackage |
| 4179 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4180 | } |
| 4181 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4182 | enforceTelephonyFeatureWithException(callingPackage, |
| 4183 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4184 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4185 | if (range == null) { |
| 4186 | throw new NullPointerException("Range must be non-null"); |
| 4187 | } |
| 4188 | |
| 4189 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4190 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4191 | |
| 4192 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4193 | } |
| 4194 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4195 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4196 | * Returns true if CDMA provisioning needs to run. |
| 4197 | */ |
| 4198 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4199 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4200 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4201 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4202 | final long identity = Binder.clearCallingIdentity(); |
| 4203 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4204 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(identity); |
| 4207 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4211 | * Sets the voice mail number of a given subId. |
| 4212 | */ |
| 4213 | @Override |
| 4214 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4215 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4216 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4217 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4218 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4219 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4221 | final long identity = Binder.clearCallingIdentity(); |
| 4222 | try { |
| 4223 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4224 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4225 | return success; |
| 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(identity); |
| 4228 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4231 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4232 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4233 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4234 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4235 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4236 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4237 | throw new SecurityException("caller must be system dialer"); |
| 4238 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4239 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4240 | enforceTelephonyFeatureWithException(callingPackage, |
| 4241 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4242 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4243 | final long identity = Binder.clearCallingIdentity(); |
| 4244 | try { |
| 4245 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4246 | if (phoneAccountHandle == null) { |
| 4247 | return null; |
| 4248 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4249 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | } finally { |
| 4251 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4252 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4256 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4257 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4258 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4259 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4260 | mApp, subId, callingPackage, callingFeatureId, |
| 4261 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4262 | return null; |
| 4263 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4264 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4265 | enforceTelephonyFeatureWithException(callingPackage, |
| 4266 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4267 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4268 | final long identity = Binder.clearCallingIdentity(); |
| 4269 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4270 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4271 | } finally { |
| 4272 | Binder.restoreCallingIdentity(identity); |
| 4273 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4277 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4278 | VisualVoicemailSmsFilterSettings settings) { |
| 4279 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4280 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4281 | enforceTelephonyFeatureWithException(callingPackage, |
| 4282 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | final long identity = Binder.clearCallingIdentity(); |
| 4284 | try { |
| 4285 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4286 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4287 | } finally { |
| 4288 | Binder.restoreCallingIdentity(identity); |
| 4289 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4293 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4294 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4295 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4296 | enforceTelephonyFeatureWithException(callingPackage, |
| 4297 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4298 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | final long identity = Binder.clearCallingIdentity(); |
| 4300 | try { |
| 4301 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4302 | mApp, callingPackage, subId); |
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 VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4310 | String callingPackage, int subId) { |
| 4311 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4312 | |
| 4313 | final long identity = Binder.clearCallingIdentity(); |
| 4314 | try { |
| 4315 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4316 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
| 4319 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4323 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4324 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4325 | |
| 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4329 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4330 | } finally { |
| 4331 | Binder.restoreCallingIdentity(identity); |
| 4332 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4336 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4337 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4338 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4339 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4340 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4341 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4342 | |
| 4343 | enforceTelephonyFeatureWithException(callingPackage, |
| 4344 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4345 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4346 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4347 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4348 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4349 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4350 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4351 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4352 | * Sets the voice activation state of a given subId. |
| 4353 | */ |
| 4354 | @Override |
| 4355 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4357 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4358 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4359 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4360 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4362 | final long identity = Binder.clearCallingIdentity(); |
| 4363 | try { |
| 4364 | final Phone phone = getPhone(subId); |
| 4365 | if (phone != null) { |
| 4366 | phone.setVoiceActivationState(activationState); |
| 4367 | } else { |
| 4368 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4369 | } |
| 4370 | } finally { |
| 4371 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4372 | } |
| 4373 | } |
| 4374 | |
| 4375 | /** |
| 4376 | * Sets the data activation state of a given subId. |
| 4377 | */ |
| 4378 | @Override |
| 4379 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4380 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4381 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4382 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4383 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4384 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4385 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4386 | final long identity = Binder.clearCallingIdentity(); |
| 4387 | try { |
| 4388 | final Phone phone = getPhone(subId); |
| 4389 | if (phone != null) { |
| 4390 | phone.setDataActivationState(activationState); |
| 4391 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4392 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4393 | } |
| 4394 | } finally { |
| 4395 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | /** |
| 4400 | * Returns the voice activation state of a given subId. |
| 4401 | */ |
| 4402 | @Override |
| 4403 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4404 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4406 | enforceTelephonyFeatureWithException(callingPackage, |
| 4407 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4408 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4409 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4410 | final long identity = Binder.clearCallingIdentity(); |
| 4411 | try { |
| 4412 | if (phone != null) { |
| 4413 | return phone.getVoiceActivationState(); |
| 4414 | } else { |
| 4415 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4416 | } |
| 4417 | } finally { |
| 4418 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | /** |
| 4423 | * Returns the data activation state of a given subId. |
| 4424 | */ |
| 4425 | @Override |
| 4426 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4427 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4428 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4429 | enforceTelephonyFeatureWithException(callingPackage, |
| 4430 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4431 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4432 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4433 | final long identity = Binder.clearCallingIdentity(); |
| 4434 | try { |
| 4435 | if (phone != null) { |
| 4436 | return phone.getDataActivationState(); |
| 4437 | } else { |
| 4438 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4439 | } |
| 4440 | } finally { |
| 4441 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4442 | } |
| 4443 | } |
| 4444 | |
| 4445 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4446 | * Returns the unread count of voicemails for a subId |
| 4447 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4448 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4449 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4450 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4451 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4452 | mApp, subId, callingPackage, callingFeatureId, |
| 4453 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4454 | return 0; |
| 4455 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4456 | final long identity = Binder.clearCallingIdentity(); |
| 4457 | try { |
| 4458 | final Phone phone = getPhone(subId); |
| 4459 | if (phone != null) { |
| 4460 | return phone.getVoiceMessageCount(); |
| 4461 | } else { |
| 4462 | return 0; |
| 4463 | } |
| 4464 | } finally { |
| 4465 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4466 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4470 | * returns true, if the device is in a state where both voice and data |
| 4471 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4472 | */ |
| 4473 | @Override |
| 4474 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4475 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4476 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4477 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4480 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4481 | } finally { |
| 4482 | Binder.restoreCallingIdentity(identity); |
| 4483 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4487 | * Send the dialer code if called from the current default dialer or the caller has |
| 4488 | * carrier privilege. |
| 4489 | * @param inputCode The dialer code to send |
| 4490 | */ |
| 4491 | @Override |
| 4492 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4493 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4494 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4495 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4496 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4497 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4498 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4499 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4500 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4501 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4502 | enforceTelephonyFeatureWithException(callingPackage, |
| 4503 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4504 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4505 | final long identity = Binder.clearCallingIdentity(); |
| 4506 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4507 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4511 | } |
| 4512 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4513 | @Override |
| 4514 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4515 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4516 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4517 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4518 | |
| 4519 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4520 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4521 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
| 4524 | if (!isActiveSubscription(subId)) { |
| 4525 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4526 | } |
| 4527 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4530 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4533 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4534 | public boolean isInEmergencySmsMode() { |
| 4535 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4536 | |
| 4537 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4538 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4539 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4540 | final long identity = Binder.clearCallingIdentity(); |
| 4541 | try { |
| 4542 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4543 | if (phone.isInEmergencySmsMode()) { |
| 4544 | return true; |
| 4545 | } |
| 4546 | } |
| 4547 | } finally { |
| 4548 | Binder.restoreCallingIdentity(identity); |
| 4549 | } |
| 4550 | return false; |
| 4551 | } |
| 4552 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4553 | /** |
| 4554 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4555 | * @param subId The subscription to use to check the configuration. |
| 4556 | * @param c The callback that will be used to send the result. |
| 4557 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4558 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4559 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4560 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4561 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4562 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4563 | |
| 4564 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4565 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4566 | "IMS not available on device."); |
| 4567 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4568 | final long token = Binder.clearCallingIdentity(); |
| 4569 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4570 | int slotId = getSlotIndexOrException(subId); |
| 4571 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4572 | |
| 4573 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4574 | if (controller != null) { |
| 4575 | ImsManager imsManager = controller.getImsManager(subId); |
| 4576 | if (imsManager != null) { |
| 4577 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4578 | } else { |
| 4579 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4580 | } |
| 4581 | } else { |
| 4582 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4583 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4584 | } catch (ImsException e) { |
| 4585 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4586 | } finally { |
| 4587 | Binder.restoreCallingIdentity(token); |
| 4588 | } |
| 4589 | } |
| 4590 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4591 | /** |
| 4592 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4593 | * @param subId The subscription to use to check the configuration. |
| 4594 | * @param c The callback that will be used to send the result. |
| 4595 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4596 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4597 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4598 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4599 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4600 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4601 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4602 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4603 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4604 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4605 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4606 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4607 | if (controller != null) { |
| 4608 | ImsManager imsManager = controller.getImsManager(subId); |
| 4609 | if (imsManager != null) { |
| 4610 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4611 | } else { |
| 4612 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4613 | + "is inactive, ignoring unregister."); |
| 4614 | // If the ImsManager is not valid, just return, since the callback |
| 4615 | // will already have been removed internally. |
| 4616 | } |
| 4617 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4618 | } finally { |
| 4619 | Binder.restoreCallingIdentity(token); |
| 4620 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4621 | } |
| 4622 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4623 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4624 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4625 | * @param subId The subscription to use to check the configuration. |
| 4626 | * @param c The callback that will be used to send the result. |
| 4627 | */ |
| 4628 | @Override |
| 4629 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4630 | throws RemoteException { |
| 4631 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4632 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4633 | |
| 4634 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4635 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4636 | "IMS not available on device."); |
| 4637 | } |
| 4638 | final long token = Binder.clearCallingIdentity(); |
| 4639 | try { |
| 4640 | int slotId = getSlotIndexOrException(subId); |
| 4641 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4642 | |
| 4643 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4644 | if (controller != null) { |
| 4645 | ImsManager imsManager = controller.getImsManager(subId); |
| 4646 | if (imsManager != null) { |
| 4647 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4648 | } else { |
| 4649 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4650 | } |
| 4651 | } else { |
| 4652 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4653 | } |
| 4654 | } catch (ImsException e) { |
| 4655 | throw new ServiceSpecificException(e.getCode()); |
| 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(token); |
| 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | /** |
| 4662 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4663 | * @param subId The subscription to use to check the configuration. |
| 4664 | * @param c The callback that will be used to send the result. |
| 4665 | */ |
| 4666 | @Override |
| 4667 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4668 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4669 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4670 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4671 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4672 | } |
| 4673 | final long token = Binder.clearCallingIdentity(); |
| 4674 | |
| 4675 | try { |
| 4676 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4677 | if (controller != null) { |
| 4678 | ImsManager imsManager = controller.getImsManager(subId); |
| 4679 | if (imsManager != null) { |
| 4680 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4681 | } else { |
| 4682 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4683 | + "is inactive, ignoring unregister."); |
| 4684 | // If the ImsManager is not valid, just return, since the callback |
| 4685 | // will already have been removed internally. |
| 4686 | } |
| 4687 | } |
| 4688 | } finally { |
| 4689 | Binder.restoreCallingIdentity(token); |
| 4690 | } |
| 4691 | } |
| 4692 | |
| 4693 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4694 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4695 | */ |
| 4696 | @Override |
| 4697 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4698 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4699 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4700 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4701 | "IMS not available on device."); |
| 4702 | } |
| 4703 | final long token = Binder.clearCallingIdentity(); |
| 4704 | try { |
| 4705 | Phone phone = getPhone(subId); |
| 4706 | if (phone == null) { |
| 4707 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4708 | + subId + "'"); |
| 4709 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4710 | } |
| 4711 | phone.getImsRegistrationState(regState -> { |
| 4712 | try { |
| 4713 | consumer.accept((regState == null) |
| 4714 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4715 | } catch (RemoteException e) { |
| 4716 | // Ignore if the remote process is no longer available to call back. |
| 4717 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4718 | } |
| 4719 | }); |
| 4720 | } finally { |
| 4721 | Binder.restoreCallingIdentity(token); |
| 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | /** |
| 4726 | * Get the transport type for the IMS service registration state. |
| 4727 | */ |
| 4728 | @Override |
| 4729 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4730 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4731 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4732 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4733 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4734 | "IMS not available on device."); |
| 4735 | } |
| 4736 | final long token = Binder.clearCallingIdentity(); |
| 4737 | try { |
| 4738 | Phone phone = getPhone(subId); |
| 4739 | if (phone == null) { |
| 4740 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4741 | + subId + "'"); |
| 4742 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4743 | } |
| 4744 | phone.getImsRegistrationTech(regTech -> { |
| 4745 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4746 | int regTechConverted = (regTech == null) |
| 4747 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4748 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4749 | regTechConverted); |
| 4750 | try { |
| 4751 | consumer.accept(regTechConverted); |
| 4752 | } catch (RemoteException e) { |
| 4753 | // Ignore if the remote process is no longer available to call back. |
| 4754 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4755 | } |
| 4756 | }); |
| 4757 | } finally { |
| 4758 | Binder.restoreCallingIdentity(token); |
| 4759 | } |
| 4760 | } |
| 4761 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4762 | /** |
| 4763 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4764 | * @param subId The subscription to use to check the configuration. |
| 4765 | * @param c The callback that will be used to send the result. |
| 4766 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4767 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4768 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4769 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4770 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4771 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4772 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4773 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4774 | "IMS not available on device."); |
| 4775 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4776 | final long token = Binder.clearCallingIdentity(); |
| 4777 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4778 | int slotId = getSlotIndexOrException(subId); |
| 4779 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4780 | |
| 4781 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4782 | if (controller != null) { |
| 4783 | ImsManager imsManager = controller.getImsManager(subId); |
| 4784 | if (imsManager != null) { |
| 4785 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4786 | } else { |
| 4787 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4788 | } |
| 4789 | } else { |
| 4790 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4791 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4792 | } catch (ImsException e) { |
| 4793 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4794 | } finally { |
| 4795 | Binder.restoreCallingIdentity(token); |
| 4796 | } |
| 4797 | } |
| 4798 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4799 | /** |
| 4800 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4801 | * @param subId The subscription to use to check the configuration. |
| 4802 | * @param c The callback that will be used to send the result. |
| 4803 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4804 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4805 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4806 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4807 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4808 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4809 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4810 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4811 | |
| 4812 | final long token = Binder.clearCallingIdentity(); |
| 4813 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4814 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4815 | if (controller != null) { |
| 4816 | ImsManager imsManager = controller.getImsManager(subId); |
| 4817 | if (imsManager != null) { |
| 4818 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4819 | } else { |
| 4820 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4821 | + " is inactive, ignoring unregister."); |
| 4822 | // If the ImsManager is not valid, just return, since the callback |
| 4823 | // will already have been removed internally. |
| 4824 | } |
| 4825 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4826 | } finally { |
| 4827 | Binder.restoreCallingIdentity(token); |
| 4828 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4829 | } |
| 4830 | |
| 4831 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4832 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4833 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4834 | |
| 4835 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4836 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4837 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4838 | final long token = Binder.clearCallingIdentity(); |
| 4839 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4840 | int slotId = getSlotIndexOrException(subId); |
| 4841 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4842 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4843 | } catch (com.android.ims.ImsException e) { |
| 4844 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4845 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4846 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4847 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4848 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4849 | } finally { |
| 4850 | Binder.restoreCallingIdentity(token); |
| 4851 | } |
| 4852 | } |
| 4853 | |
| 4854 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4855 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4856 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4857 | |
| 4858 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4859 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4860 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4861 | final long token = Binder.clearCallingIdentity(); |
| 4862 | try { |
| 4863 | Phone phone = getPhone(subId); |
| 4864 | if (phone == null) return false; |
| 4865 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4866 | } catch (com.android.ims.ImsException e) { |
| 4867 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4868 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(token); |
| 4871 | } |
| 4872 | } |
| 4873 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4874 | /** |
| 4875 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4876 | * subscription. |
| 4877 | * @param subId The subscription to use to check the configuration. |
| 4878 | * @param callback The callback that will be used to send the result. |
| 4879 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4880 | * @param transportType The transport type of the MmTelFeature capability. |
| 4881 | */ |
| 4882 | @Override |
| 4883 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4884 | int transportType) { |
| 4885 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4886 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4887 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4888 | "IMS not available on device."); |
| 4889 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4890 | final long token = Binder.clearCallingIdentity(); |
| 4891 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4892 | int slotId = getSlotIndex(subId); |
| 4893 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4894 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4895 | + subId + "'"); |
| 4896 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4897 | } |
| 4898 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4899 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4900 | transportType, aBoolean -> { |
| 4901 | try { |
| 4902 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4903 | } catch (RemoteException e) { |
| 4904 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4905 | + "running. Ignore"); |
| 4906 | } |
| 4907 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4908 | } catch (ImsException e) { |
| 4909 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4910 | } finally { |
| 4911 | Binder.restoreCallingIdentity(token); |
| 4912 | } |
| 4913 | } |
| 4914 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4915 | /** |
| 4916 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4917 | * @param subId The subscription to use to check the configuration. |
| 4918 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4919 | @Override |
| 4920 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4921 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4922 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4923 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4924 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4925 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4926 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4927 | final long token = Binder.clearCallingIdentity(); |
| 4928 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4929 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4930 | // 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] | 4931 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4932 | } catch (ImsException e) { |
| 4933 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4934 | } finally { |
| 4935 | Binder.restoreCallingIdentity(token); |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4940 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4941 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4942 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4943 | |
| 4944 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4945 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4946 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4947 | final long identity = Binder.clearCallingIdentity(); |
| 4948 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4949 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4950 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4951 | // 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] | 4952 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4953 | } catch (ImsException e) { |
| 4954 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4955 | } finally { |
| 4956 | Binder.restoreCallingIdentity(identity); |
| 4957 | } |
| 4958 | } |
| 4959 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4960 | /** |
| 4961 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4962 | * @param subId The subscription to use to check the configuration. |
| 4963 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4964 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4965 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4966 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4967 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4968 | |
| 4969 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4970 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4971 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4972 | final long identity = Binder.clearCallingIdentity(); |
| 4973 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4974 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4975 | // 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] | 4976 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4977 | } catch (ImsException e) { |
| 4978 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4979 | } finally { |
| 4980 | Binder.restoreCallingIdentity(identity); |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4985 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4987 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4988 | |
| 4989 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4990 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4991 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4992 | final long identity = Binder.clearCallingIdentity(); |
| 4993 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4994 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4995 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4996 | // 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] | 4997 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4998 | } catch (ImsException e) { |
| 4999 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5000 | } finally { |
| 5001 | Binder.restoreCallingIdentity(identity); |
| 5002 | } |
| 5003 | } |
| 5004 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5005 | /** |
| 5006 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5007 | * @param subId The subscription to use to check the configuration. |
| 5008 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5009 | @Override |
| 5010 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5011 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5012 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5013 | |
| 5014 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5015 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5016 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5017 | final long identity = Binder.clearCallingIdentity(); |
| 5018 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5019 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5020 | // 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] | 5021 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5022 | } catch (ImsException e) { |
| 5023 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
| 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5030 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5032 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5033 | |
| 5034 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5035 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5036 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5037 | final long identity = Binder.clearCallingIdentity(); |
| 5038 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5039 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5040 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5041 | // 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] | 5042 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5043 | } catch (ImsException e) { |
| 5044 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5045 | } finally { |
| 5046 | Binder.restoreCallingIdentity(identity); |
| 5047 | } |
| 5048 | } |
| 5049 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5050 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5051 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5052 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5053 | * @param subId The subscription to use to check the configuration. |
| 5054 | */ |
| 5055 | @Override |
| 5056 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5057 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5058 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5059 | |
| 5060 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5061 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5062 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5063 | final long identity = Binder.clearCallingIdentity(); |
| 5064 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5065 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5066 | // 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] | 5067 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5068 | } catch (ImsException e) { |
| 5069 | throw new ServiceSpecificException(e.getCode()); |
| 5070 | } finally { |
| 5071 | Binder.restoreCallingIdentity(identity); |
| 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | /** |
| 5076 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5077 | * Requires MODIFY_PHONE_STATE permission. |
| 5078 | * @param subId The subscription to use to check the configuration. |
| 5079 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5080 | * false otherwise |
| 5081 | */ |
| 5082 | @Override |
| 5083 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5085 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5086 | |
| 5087 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5088 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5089 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5090 | final long identity = Binder.clearCallingIdentity(); |
| 5091 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5092 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5093 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5094 | // 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] | 5095 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5096 | } catch (ImsException e) { |
| 5097 | throw new ServiceSpecificException(e.getCode()); |
| 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
| 5100 | } |
| 5101 | } |
| 5102 | |
| 5103 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5104 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5105 | * @param subId The subscription to use to check the configuration. |
| 5106 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5107 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5108 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5109 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5110 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5111 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5112 | |
| 5113 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5114 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5115 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5116 | final long identity = Binder.clearCallingIdentity(); |
| 5117 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5118 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5119 | // 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] | 5120 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5121 | } catch (ImsException e) { |
| 5122 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5123 | } finally { |
| 5124 | Binder.restoreCallingIdentity(identity); |
| 5125 | } |
| 5126 | } |
| 5127 | |
| 5128 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5129 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5131 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5132 | |
| 5133 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5134 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5135 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5136 | final long identity = Binder.clearCallingIdentity(); |
| 5137 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5138 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5139 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5140 | // 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] | 5141 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5142 | } catch (ImsException e) { |
| 5143 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
| 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | @Override |
| 5150 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5152 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5153 | |
| 5154 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5155 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5156 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5157 | final long identity = Binder.clearCallingIdentity(); |
| 5158 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5159 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5160 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5161 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5162 | } catch (ImsException e) { |
| 5163 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
| 5166 | } |
| 5167 | } |
| 5168 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5169 | /** |
| 5170 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5171 | * @param subId The subscription to use to check the configuration. |
| 5172 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5173 | @Override |
| 5174 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5175 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5176 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5177 | |
| 5178 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5179 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5180 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5181 | final long identity = Binder.clearCallingIdentity(); |
| 5182 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5183 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5184 | // 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] | 5185 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5186 | } catch (ImsException e) { |
| 5187 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5188 | } finally { |
| 5189 | Binder.restoreCallingIdentity(identity); |
| 5190 | } |
| 5191 | } |
| 5192 | |
| 5193 | @Override |
| 5194 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5196 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5197 | |
| 5198 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5199 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5200 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5201 | final long identity = Binder.clearCallingIdentity(); |
| 5202 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5203 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5204 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5205 | // 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] | 5206 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5207 | } catch (ImsException e) { |
| 5208 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | @Override |
| 5215 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5216 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5217 | |
| 5218 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5219 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5220 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5223 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5224 | // 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] | 5225 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5226 | } catch (ImsException e) { |
| 5227 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | @Override |
| 5234 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5236 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5237 | |
| 5238 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5239 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5240 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5241 | final long identity = Binder.clearCallingIdentity(); |
| 5242 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5243 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5244 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5245 | // 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] | 5246 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5247 | } catch (ImsException e) { |
| 5248 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5249 | } finally { |
| 5250 | Binder.restoreCallingIdentity(identity); |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | @Override |
| 5255 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5256 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5257 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5258 | |
| 5259 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5260 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5261 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5262 | final long identity = Binder.clearCallingIdentity(); |
| 5263 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5264 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5265 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5266 | // 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] | 5267 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5268 | } catch (ImsException e) { |
| 5269 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5270 | } finally { |
| 5271 | Binder.restoreCallingIdentity(identity); |
| 5272 | } |
| 5273 | } |
| 5274 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5275 | /** |
| 5276 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5277 | * @param subId The subscription to use to check the configuration. |
| 5278 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5279 | @Override |
| 5280 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5281 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5282 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5283 | |
| 5284 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5285 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5286 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5287 | final long identity = Binder.clearCallingIdentity(); |
| 5288 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5289 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5290 | // 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] | 5291 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5292 | } catch (ImsException e) { |
| 5293 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5294 | } finally { |
| 5295 | Binder.restoreCallingIdentity(identity); |
| 5296 | } |
| 5297 | } |
| 5298 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5299 | @Override |
| 5300 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5301 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5302 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5303 | final long identity = Binder.clearCallingIdentity(); |
| 5304 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5305 | if (!isImsAvailableOnDevice()) { |
| 5306 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5307 | "IMS not available on device."); |
| 5308 | } |
| 5309 | int slotId = getSlotIndexOrException(subId); |
| 5310 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5311 | |
| 5312 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5313 | if (controller != null) { |
| 5314 | ImsManager imsManager = controller.getImsManager(subId); |
| 5315 | if (imsManager != null) { |
| 5316 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5317 | } else { |
| 5318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5319 | } |
| 5320 | } else { |
| 5321 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5322 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5323 | } catch (ImsException e) { |
| 5324 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5325 | } finally { |
| 5326 | Binder.restoreCallingIdentity(identity); |
| 5327 | } |
| 5328 | } |
| 5329 | |
| 5330 | @Override |
| 5331 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5332 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5333 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5334 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5335 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5336 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5337 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5338 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5339 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5340 | if (controller != null) { |
| 5341 | ImsManager imsManager = controller.getImsManager(subId); |
| 5342 | if (imsManager != null) { |
| 5343 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5344 | } else { |
| 5345 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5346 | + " is inactive, ignoring unregister."); |
| 5347 | // If the ImsManager is not valid, just return, since the callback will already |
| 5348 | // have been removed internally. |
| 5349 | } |
| 5350 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5351 | } finally { |
| 5352 | Binder.restoreCallingIdentity(identity); |
| 5353 | } |
| 5354 | } |
| 5355 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5356 | @Override |
| 5357 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5358 | IFeatureProvisioningCallback callback) { |
| 5359 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5360 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5361 | |
| 5362 | final long identity = Binder.clearCallingIdentity(); |
| 5363 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5364 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5365 | } |
| 5366 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5367 | try { |
| 5368 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5369 | if (controller == null) { |
| 5370 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5371 | "Device does not support IMS"); |
| 5372 | } |
| 5373 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5374 | } finally { |
| 5375 | Binder.restoreCallingIdentity(identity); |
| 5376 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | @Override |
| 5380 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5381 | IFeatureProvisioningCallback callback) { |
| 5382 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5383 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5384 | |
| 5385 | final long identity = Binder.clearCallingIdentity(); |
| 5386 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5387 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5388 | } |
| 5389 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5390 | try { |
| 5391 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5392 | if (controller == null) { |
| 5393 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5394 | return; |
| 5395 | } |
| 5396 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5397 | } finally { |
| 5398 | Binder.restoreCallingIdentity(identity); |
| 5399 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5400 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5401 | |
| 5402 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5403 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5404 | message); |
| 5405 | } |
| 5406 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5407 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5408 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5409 | boolean isProvisioned) { |
| 5410 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5411 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5412 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5413 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5414 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5415 | final long identity = Binder.clearCallingIdentity(); |
| 5416 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5417 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5418 | if (controller == null) { |
| 5419 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5420 | return; |
| 5421 | } |
| 5422 | controller.setRcsProvisioningStatusForCapability( |
| 5423 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5424 | } finally { |
| 5425 | Binder.restoreCallingIdentity(identity); |
| 5426 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | |
| 5430 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5431 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5432 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5433 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5434 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5435 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5436 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5437 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5438 | final long identity = Binder.clearCallingIdentity(); |
| 5439 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5440 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5441 | if (controller == null) { |
| 5442 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5443 | |
| 5444 | // device does not support IMS, this method will return true always. |
| 5445 | return true; |
| 5446 | } |
| 5447 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5448 | } finally { |
| 5449 | Binder.restoreCallingIdentity(identity); |
| 5450 | } |
| 5451 | } |
| 5452 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5453 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5454 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5455 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5456 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5457 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5458 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5459 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5460 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5461 | final long identity = Binder.clearCallingIdentity(); |
| 5462 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5463 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5464 | if (controller == null) { |
| 5465 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5466 | return; |
| 5467 | } |
| 5468 | controller.setImsProvisioningStatusForCapability( |
| 5469 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5470 | } finally { |
| 5471 | Binder.restoreCallingIdentity(identity); |
| 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | @Override |
| 5476 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5477 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5478 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5479 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5480 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5481 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5482 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5485 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5486 | if (controller == null) { |
| 5487 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5488 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5489 | // device does not support IMS, this method will return true always. |
| 5490 | return true; |
| 5491 | } |
| 5492 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5499 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5500 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5501 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5502 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5503 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5504 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5505 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5506 | final long identity = Binder.clearCallingIdentity(); |
| 5507 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5508 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5509 | if (controller == null) { |
| 5510 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5511 | |
| 5512 | // device does not support IMS, this method will return false |
| 5513 | return false; |
| 5514 | } |
| 5515 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5516 | } finally { |
| 5517 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5518 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5522 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5523 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5524 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5525 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5526 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5527 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5528 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5529 | final long identity = Binder.clearCallingIdentity(); |
| 5530 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5531 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5532 | if (controller == null) { |
| 5533 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5534 | |
| 5535 | // device does not support IMS, this method will return false |
| 5536 | return false; |
| 5537 | } |
| 5538 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5539 | } finally { |
| 5540 | Binder.restoreCallingIdentity(identity); |
| 5541 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5542 | } |
| 5543 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5544 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5545 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5546 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5547 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5548 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5549 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5550 | mApp, subId, "getImsProvisioningInt"); |
| 5551 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5552 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5553 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5554 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5555 | final long identity = Binder.clearCallingIdentity(); |
| 5556 | try { |
| 5557 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5558 | int slotId = getSlotIndex(subId); |
| 5559 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5560 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5561 | + subId + "' for key:" + key); |
| 5562 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5563 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5564 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5565 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5566 | if (controller == null) { |
| 5567 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5568 | |
| 5569 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5570 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5571 | } |
| 5572 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5573 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5574 | return retVal; |
| 5575 | } |
| 5576 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5577 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5578 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5579 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5580 | + subId + "' for key:" + key); |
| 5581 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5582 | } finally { |
| 5583 | Binder.restoreCallingIdentity(identity); |
| 5584 | } |
| 5585 | } |
| 5586 | |
| 5587 | @Override |
| 5588 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5589 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5590 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5591 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5592 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5593 | mApp, subId, "getImsProvisioningString"); |
| 5594 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5595 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5596 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5597 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5598 | final long identity = Binder.clearCallingIdentity(); |
| 5599 | try { |
| 5600 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5601 | int slotId = getSlotIndex(subId); |
| 5602 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5603 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5604 | + subId + "' for key:" + key); |
| 5605 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5606 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5607 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5608 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5609 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5610 | + subId + "' for key:" + key); |
| 5611 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5612 | } finally { |
| 5613 | Binder.restoreCallingIdentity(identity); |
| 5614 | } |
| 5615 | } |
| 5616 | |
| 5617 | @Override |
| 5618 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5619 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5620 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5621 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5623 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5624 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5625 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5626 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5627 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5628 | final long identity = Binder.clearCallingIdentity(); |
| 5629 | try { |
| 5630 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5631 | int slotId = getSlotIndex(subId); |
| 5632 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5633 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5634 | + subId + "' for key:" + key); |
| 5635 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5636 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5637 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5638 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5639 | if (controller == null) { |
| 5640 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5641 | |
| 5642 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5643 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5644 | } |
| 5645 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5646 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5647 | return retVal; |
| 5648 | } |
| 5649 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5650 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5651 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5652 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5653 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5654 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5655 | } finally { |
| 5656 | Binder.restoreCallingIdentity(identity); |
| 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | @Override |
| 5661 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5662 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5663 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5664 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5666 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5667 | |
| 5668 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5669 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5670 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5671 | final long identity = Binder.clearCallingIdentity(); |
| 5672 | try { |
| 5673 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5674 | int slotId = getSlotIndex(subId); |
| 5675 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5676 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5677 | + subId + "' for key:" + key); |
| 5678 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5679 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5680 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5681 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5682 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5683 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5684 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5685 | } finally { |
| 5686 | Binder.restoreCallingIdentity(identity); |
| 5687 | } |
| 5688 | } |
| 5689 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5690 | /** |
| 5691 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5692 | * for the given slot ID or no ImsResolver instance has been created. |
| 5693 | * @param slotId The slot ID that the IMS service is created for. |
| 5694 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5695 | */ |
| 5696 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5697 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5698 | ImsFeature.FEATURE_MMTEL)) { |
| 5699 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5700 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5701 | } |
| 5702 | } |
| 5703 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5704 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5705 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5706 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5707 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5708 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5709 | } |
| 5710 | return slotId; |
| 5711 | } |
| 5712 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5713 | private int getSlotIndex(int subId) { |
| 5714 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5715 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5716 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5717 | } |
| 5718 | return slotId; |
| 5719 | } |
| 5720 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5721 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5722 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5723 | */ |
| 5724 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5725 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5726 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5727 | try { |
| 5728 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5729 | } catch (SecurityException se) { |
| 5730 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5731 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5732 | + Binder.getCallingUid()); |
| 5733 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5734 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5735 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5736 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5737 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5738 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5739 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5740 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5741 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5742 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5743 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5744 | enforceTelephonyFeatureWithException(callingPackage, |
| 5745 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | final long identity = Binder.clearCallingIdentity(); |
| 5748 | try { |
| 5749 | final Phone phone = getPhone(subId); |
| 5750 | if (phone != null) { |
| 5751 | return phone.getServiceState().getDataNetworkType(); |
| 5752 | } else { |
| 5753 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5754 | } |
| 5755 | } finally { |
| 5756 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5757 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | /** |
| 5761 | * Returns the data network type |
| 5762 | */ |
| 5763 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5764 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5765 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5766 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5767 | } |
| 5768 | |
| 5769 | /** |
| 5770 | * Returns the data network type for a subId |
| 5771 | */ |
| 5772 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5773 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5774 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5775 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5776 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5777 | mApp, functionName)) { |
| 5778 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5779 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5780 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5781 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5784 | enforceTelephonyFeatureWithException(callingPackage, |
| 5785 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5786 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5787 | final long identity = Binder.clearCallingIdentity(); |
| 5788 | try { |
| 5789 | final Phone phone = getPhone(subId); |
| 5790 | if (phone != null) { |
| 5791 | return phone.getServiceState().getDataNetworkType(); |
| 5792 | } else { |
| 5793 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5794 | } |
| 5795 | } finally { |
| 5796 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5797 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5801 | * Returns the Voice network type for a subId |
| 5802 | */ |
| 5803 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5804 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5805 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5806 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5807 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5808 | mApp, functionName)) { |
| 5809 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5810 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5811 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5812 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5813 | } |
| 5814 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5815 | enforceTelephonyFeatureWithException(callingPackage, |
| 5816 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5817 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | final long identity = Binder.clearCallingIdentity(); |
| 5819 | try { |
| 5820 | final Phone phone = getPhone(subId); |
| 5821 | if (phone != null) { |
| 5822 | return phone.getServiceState().getVoiceNetworkType(); |
| 5823 | } else { |
| 5824 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5825 | } |
| 5826 | } finally { |
| 5827 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5828 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | /** |
| 5832 | * @return true if a ICC card is present |
| 5833 | */ |
| 5834 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5835 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5836 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5837 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5841 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5842 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5843 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5844 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5845 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5846 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5847 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5848 | final long identity = Binder.clearCallingIdentity(); |
| 5849 | try { |
| 5850 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5851 | if (phone != null) { |
| 5852 | return phone.getIccCard().hasIccCard(); |
| 5853 | } else { |
| 5854 | return false; |
| 5855 | } |
| 5856 | } finally { |
| 5857 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | /** |
| 5862 | * Return if the current radio is LTE on CDMA. This |
| 5863 | * is a tri-state return value as for a period of time |
| 5864 | * the mode may be unknown. |
| 5865 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5866 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5867 | * @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] | 5868 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5869 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5870 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5871 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5872 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5873 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5874 | } |
| 5875 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5876 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5877 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5878 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5879 | try { |
| 5880 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5881 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5882 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5883 | } |
| 5884 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5885 | enforceTelephonyFeatureWithException(callingPackage, |
| 5886 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5888 | final long identity = Binder.clearCallingIdentity(); |
| 5889 | try { |
| 5890 | final Phone phone = getPhone(subId); |
| 5891 | if (phone == null) { |
| 5892 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5893 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5894 | return TelephonyProperties.lte_on_cdma_device() |
| 5895 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5896 | } |
| 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5899 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5900 | } |
| 5901 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5902 | /** |
| 5903 | * {@hide} |
| 5904 | * Returns Default subId, 0 in the case of single standby. |
| 5905 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5906 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5907 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5910 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5911 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5912 | } |
| 5913 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5914 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5915 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5916 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5917 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5918 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5919 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5920 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5921 | } |
| 5922 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5923 | /** |
| 5924 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5925 | */ |
| 5926 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | final long identity = Binder.clearCallingIdentity(); |
| 5928 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5929 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5931 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5932 | } finally { |
| 5933 | Binder.restoreCallingIdentity(identity); |
| 5934 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | /** |
| 5938 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5939 | */ |
| 5940 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5941 | final long identity = Binder.clearCallingIdentity(); |
| 5942 | try { |
| 5943 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5944 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5945 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5946 | } finally { |
| 5947 | Binder.restoreCallingIdentity(identity); |
| 5948 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5949 | } |
| 5950 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5951 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5952 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5953 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5954 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5955 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5956 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5957 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5958 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5959 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5960 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5961 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5962 | } |
| 5963 | return PhoneFactory.getPhone(phoneId); |
| 5964 | } |
| 5965 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5966 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5967 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5968 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5969 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5970 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5971 | /*message=*/ "iccOpenLogicalChannel"); |
| 5972 | |
| 5973 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5974 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5975 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5976 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5977 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5978 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5979 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5980 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5981 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5982 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5983 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5984 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5985 | Phone phone; |
| 5986 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5987 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5988 | mApp, request.subId, message); |
| 5989 | phone = getPhoneFromSubId(request.subId); |
| 5990 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5991 | enforceModifyPermission(); |
| 5992 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5993 | } else { |
| 5994 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5995 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5996 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6000 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | final long identity = Binder.clearCallingIdentity(); |
| 6002 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6003 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6004 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6005 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6006 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6007 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6008 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | loge("The calling package is not allowed to access ISD-R."); |
| 6010 | throw new SecurityException( |
| 6011 | "The calling package is not allowed to access ISD-R."); |
| 6012 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6013 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6014 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6016 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6017 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6018 | return response; |
| 6019 | } finally { |
| 6020 | Binder.restoreCallingIdentity(identity); |
| 6021 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6025 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6026 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6027 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6028 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6029 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6030 | /*message=*/"iccCloseLogicalChannel"); |
| 6031 | |
| 6032 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6033 | |
| 6034 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6035 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6036 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6037 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6038 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6039 | // before this feature is enabled, this API should only return false if |
| 6040 | // the operation fails instead of throwing runtime exception for |
| 6041 | // backward-compatibility. |
| 6042 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6043 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6044 | final long identity = Binder.clearCallingIdentity(); |
| 6045 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6046 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6047 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6048 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6049 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6050 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6051 | Boolean success = false; |
| 6052 | if (result instanceof RuntimeException) { |
| 6053 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6054 | if (shouldThrowExceptionOnFailure) { |
| 6055 | throw (RuntimeException) result; |
| 6056 | } else { |
| 6057 | return false; |
| 6058 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6059 | } else if (result instanceof Boolean) { |
| 6060 | success = (Boolean) result; |
| 6061 | } else { |
| 6062 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6063 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6064 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6065 | return success; |
| 6066 | } finally { |
| 6067 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6068 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6069 | } |
| 6070 | |
| 6071 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6072 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6073 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6075 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6076 | |
| 6077 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6078 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6079 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6080 | if (DBG) { |
| 6081 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6082 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6083 | + p3 + " data=" + data); |
| 6084 | } |
| 6085 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6086 | command, p1, p2, p3, data); |
| 6087 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6088 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6089 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6090 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6091 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6092 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6093 | |
| 6094 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6095 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6096 | "iccTransmitApduLogicalChannelBySlot"); |
| 6097 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6098 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6099 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6100 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6101 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6102 | } |
| 6103 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6104 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6105 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6109 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | final long identity = Binder.clearCallingIdentity(); |
| 6111 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6112 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6113 | return ""; |
| 6114 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6115 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6117 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6118 | null /* workSource */); |
| 6119 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6120 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6121 | // Append the returned status code to the end of the response payload. |
| 6122 | String s = Integer.toHexString( |
| 6123 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6124 | if (response.payload != null) { |
| 6125 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6126 | } |
| 6127 | return s; |
| 6128 | } finally { |
| 6129 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6130 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6131 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6132 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6133 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6134 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6135 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6136 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6137 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6138 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6139 | |
| 6140 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6141 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6142 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6143 | if (DBG) { |
| 6144 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6145 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6146 | } |
| 6147 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6148 | cla, command, p1, p2, p3, data); |
| 6149 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6150 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6151 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6152 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6153 | 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] | 6154 | enforceModifyPermission(); |
| 6155 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6156 | |
| 6157 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6158 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6159 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6160 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6161 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6162 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6163 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6167 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6168 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6172 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6173 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6174 | final long identity = Binder.clearCallingIdentity(); |
| 6175 | try { |
| 6176 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6177 | && TextUtils.equals(ISDR_AID, data)) { |
| 6178 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6179 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6180 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6181 | if (bestComponent == null |
| 6182 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6183 | loge("The calling package is not allowed to select ISD-R."); |
| 6184 | throw new SecurityException( |
| 6185 | "The calling package is not allowed to select ISD-R."); |
| 6186 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6187 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6188 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6189 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6190 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6191 | null /* workSource */); |
| 6192 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6193 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | // Append the returned status code to the end of the response payload. |
| 6195 | String s = Integer.toHexString( |
| 6196 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6197 | if (response.payload != null) { |
| 6198 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6199 | } |
| 6200 | return s; |
| 6201 | } finally { |
| 6202 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6203 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6207 | 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] | 6208 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6210 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6211 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6212 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6213 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6215 | final long identity = Binder.clearCallingIdentity(); |
| 6216 | try { |
| 6217 | if (DBG) { |
| 6218 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6219 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6220 | } |
| 6221 | |
| 6222 | IccIoResult response = |
| 6223 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6224 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6225 | subId); |
| 6226 | |
| 6227 | if (DBG) { |
| 6228 | log("Exchange SIM_IO [R]" + response); |
| 6229 | } |
| 6230 | |
| 6231 | byte[] result = null; |
| 6232 | int length = 2; |
| 6233 | if (response.payload != null) { |
| 6234 | length = 2 + response.payload.length; |
| 6235 | result = new byte[length]; |
| 6236 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6237 | } else { |
| 6238 | result = new byte[length]; |
| 6239 | } |
| 6240 | |
| 6241 | result[length - 1] = (byte) response.sw2; |
| 6242 | result[length - 2] = (byte) response.sw1; |
| 6243 | return result; |
| 6244 | } finally { |
| 6245 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6246 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6247 | } |
| 6248 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6249 | /** |
| 6250 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6251 | * on a particular subscription |
| 6252 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6253 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6254 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6255 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6256 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6257 | return null; |
| 6258 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6260 | enforceTelephonyFeatureWithException(callingPackage, |
| 6261 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6263 | final long identity = Binder.clearCallingIdentity(); |
| 6264 | try { |
| 6265 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6266 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6267 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6268 | return null; |
| 6269 | } |
| 6270 | Object response = sendRequest( |
| 6271 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6272 | if (response instanceof String[]) { |
| 6273 | return (String[]) response; |
| 6274 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6275 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6276 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6277 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6278 | } finally { |
| 6279 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6280 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6281 | } |
| 6282 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6283 | /** |
| 6284 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6285 | * subscription. |
| 6286 | * |
| 6287 | * @param subId the id of the subscription. |
| 6288 | * @param appType the uicc app type, must be USIM or SIM. |
| 6289 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6290 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6291 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6292 | * @return number of fplmns that is successfully written to the SIM. |
| 6293 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6294 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6295 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6296 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6297 | mApp, subId, "setForbiddenPlmns"); |
| 6298 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6299 | enforceTelephonyFeatureWithException(callingPackage, |
| 6300 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6301 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6302 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6303 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6304 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6305 | } |
| 6306 | if (fplmns == null) { |
| 6307 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6308 | } |
| 6309 | for (String fplmn : fplmns) { |
| 6310 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6311 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6312 | } |
| 6313 | } |
| 6314 | final long identity = Binder.clearCallingIdentity(); |
| 6315 | try { |
| 6316 | Object response = sendRequest( |
| 6317 | CMD_SET_FORBIDDEN_PLMNS, |
| 6318 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6319 | subId); |
| 6320 | return (int) response; |
| 6321 | } finally { |
| 6322 | Binder.restoreCallingIdentity(identity); |
| 6323 | } |
| 6324 | } |
| 6325 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6326 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6327 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6329 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6330 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6331 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6332 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | final long identity = Binder.clearCallingIdentity(); |
| 6335 | try { |
| 6336 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6337 | if (response.payload == null) { |
| 6338 | return ""; |
| 6339 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6341 | // Append the returned status code to the end of the response payload. |
| 6342 | String s = Integer.toHexString( |
| 6343 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6344 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6345 | return s; |
| 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(identity); |
| 6348 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6351 | /** |
| 6352 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6353 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6354 | * |
| 6355 | * @param itemID the ID of the item to read |
| 6356 | * @return the NV item as a String, or null on error. |
| 6357 | */ |
| 6358 | @Override |
| 6359 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6360 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6361 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6362 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6363 | |
| 6364 | final long identity = Binder.clearCallingIdentity(); |
| 6365 | try { |
| 6366 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6367 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6368 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6369 | return value; |
| 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
| 6372 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | /** |
| 6376 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6377 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6378 | * |
| 6379 | * @param itemID the ID of the item to read |
| 6380 | * @param itemValue the value to write, as a String |
| 6381 | * @return true on success; false on any failure |
| 6382 | */ |
| 6383 | @Override |
| 6384 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6385 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6386 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6387 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6388 | |
| 6389 | final long identity = Binder.clearCallingIdentity(); |
| 6390 | try { |
| 6391 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6392 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6393 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6394 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6395 | return success; |
| 6396 | } finally { |
| 6397 | Binder.restoreCallingIdentity(identity); |
| 6398 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | /** |
| 6402 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6403 | * Used for device configuration by some CDMA operators. |
| 6404 | * |
| 6405 | * @param preferredRoamingList byte array containing the new PRL |
| 6406 | * @return true on success; false on any failure |
| 6407 | */ |
| 6408 | @Override |
| 6409 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6410 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6411 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | |
| 6413 | final long identity = Binder.clearCallingIdentity(); |
| 6414 | try { |
| 6415 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6416 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6417 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6418 | return success; |
| 6419 | } finally { |
| 6420 | Binder.restoreCallingIdentity(identity); |
| 6421 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6425 | * 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] | 6426 | * Used for device configuration by some CDMA operators. |
| 6427 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6428 | * @param slotIndex - device slot. |
| 6429 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6430 | * @return true on success; false on any failure |
| 6431 | */ |
| 6432 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6433 | public boolean resetModemConfig(int slotIndex) { |
| 6434 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6435 | if (phone != null) { |
| 6436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6437 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6438 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6439 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6440 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6441 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6445 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6446 | return success; |
| 6447 | } finally { |
| 6448 | Binder.restoreCallingIdentity(identity); |
| 6449 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6450 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6451 | return false; |
| 6452 | } |
| 6453 | |
| 6454 | /** |
| 6455 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6456 | * |
| 6457 | * @param slotIndex - device slot. |
| 6458 | * |
| 6459 | * @return true on success; false on any failure |
| 6460 | */ |
| 6461 | @Override |
| 6462 | public boolean rebootModem(int slotIndex) { |
| 6463 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6464 | if (phone != null) { |
| 6465 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6466 | mApp, phone.getSubId(), "rebootModem"); |
| 6467 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6468 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6469 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6470 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6471 | final long identity = Binder.clearCallingIdentity(); |
| 6472 | try { |
| 6473 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6474 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6475 | return success; |
| 6476 | } finally { |
| 6477 | Binder.restoreCallingIdentity(identity); |
| 6478 | } |
| 6479 | } |
| 6480 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6481 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6482 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6483 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6484 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6485 | * {@link #disableIms(int)}. |
| 6486 | * @param slotIndex device slot. |
| 6487 | */ |
| 6488 | public void resetIms(int slotIndex) { |
| 6489 | enforceModifyPermission(); |
| 6490 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6491 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6492 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6493 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6494 | final long identity = Binder.clearCallingIdentity(); |
| 6495 | try { |
| 6496 | if (mImsResolver == null) { |
| 6497 | // may happen if the does not support IMS. |
| 6498 | return; |
| 6499 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6500 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6501 | } finally { |
| 6502 | Binder.restoreCallingIdentity(identity); |
| 6503 | } |
| 6504 | } |
| 6505 | |
| 6506 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6507 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6508 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6509 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6510 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6511 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6512 | |
| 6513 | final long identity = Binder.clearCallingIdentity(); |
| 6514 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6515 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6516 | // may happen if the device does not support IMS. |
| 6517 | return; |
| 6518 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6519 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6520 | } finally { |
| 6521 | Binder.restoreCallingIdentity(identity); |
| 6522 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6523 | } |
| 6524 | |
| 6525 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6526 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6527 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6528 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6529 | public void disableIms(int slotId) { |
| 6530 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6531 | |
| 6532 | final long identity = Binder.clearCallingIdentity(); |
| 6533 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6534 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6535 | // may happen if the device does not support IMS. |
| 6536 | return; |
| 6537 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6538 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6539 | } finally { |
| 6540 | Binder.restoreCallingIdentity(identity); |
| 6541 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6542 | } |
| 6543 | |
| 6544 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6545 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6546 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6547 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6548 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6549 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6550 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | |
| 6552 | final long identity = Binder.clearCallingIdentity(); |
| 6553 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6554 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6555 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6556 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6557 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6558 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6559 | } finally { |
| 6560 | Binder.restoreCallingIdentity(identity); |
| 6561 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6562 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6563 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6564 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6565 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6566 | @Override |
| 6567 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6568 | enforceModifyPermission(); |
| 6569 | |
| 6570 | final long identity = Binder.clearCallingIdentity(); |
| 6571 | try { |
| 6572 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6573 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6574 | } finally { |
| 6575 | Binder.restoreCallingIdentity(identity); |
| 6576 | } |
| 6577 | } |
| 6578 | |
| 6579 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6580 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6581 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6582 | */ |
| 6583 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6584 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 | |
| 6586 | final long identity = Binder.clearCallingIdentity(); |
| 6587 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6588 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6589 | // may happen if the device does not support IMS. |
| 6590 | return null; |
| 6591 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6592 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6593 | } finally { |
| 6594 | Binder.restoreCallingIdentity(identity); |
| 6595 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6596 | } |
| 6597 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6598 | /** |
| 6599 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6600 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6601 | */ |
| 6602 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6603 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6604 | |
| 6605 | final long identity = Binder.clearCallingIdentity(); |
| 6606 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6607 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6608 | // may happen if the device does not support IMS. |
| 6609 | return null; |
| 6610 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6611 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6615 | } |
| 6616 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6617 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6618 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6619 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6620 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6621 | * @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] | 6622 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6623 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6624 | * @param packageName The name of the package that the current configuration will be replaced |
| 6625 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6626 | * @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] | 6627 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6628 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6629 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6630 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6632 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6633 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6634 | final long identity = Binder.clearCallingIdentity(); |
| 6635 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6636 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6637 | // may happen if the device does not support IMS. |
| 6638 | return false; |
| 6639 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6640 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6641 | for (int featureType : featureTypes) { |
| 6642 | featureConfig.put(featureType, packageName); |
| 6643 | } |
| 6644 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6645 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6646 | } finally { |
| 6647 | Binder.restoreCallingIdentity(identity); |
| 6648 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6649 | } |
| 6650 | |
| 6651 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6652 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6653 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6654 | * |
| 6655 | * This should only be used for testing. |
| 6656 | * |
| 6657 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6658 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6659 | */ |
| 6660 | @Override |
| 6661 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6662 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6663 | "clearCarrierImsServiceOverride"); |
| 6664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6665 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6666 | |
| 6667 | final long identity = Binder.clearCallingIdentity(); |
| 6668 | try { |
| 6669 | if (mImsResolver == null) { |
| 6670 | // may happen if the device does not support IMS. |
| 6671 | return false; |
| 6672 | } |
| 6673 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6674 | } finally { |
| 6675 | Binder.restoreCallingIdentity(identity); |
| 6676 | } |
| 6677 | } |
| 6678 | |
| 6679 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6680 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6681 | * |
| 6682 | * @param slotId The slot that the ImsService is associated with. |
| 6683 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6684 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6685 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6686 | * @return the package name of the ImsService configuration. |
| 6687 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6688 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6689 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6690 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6691 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6692 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | final long identity = Binder.clearCallingIdentity(); |
| 6695 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6696 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6697 | // may happen if the device does not support IMS. |
| 6698 | return ""; |
| 6699 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6700 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6701 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6702 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6703 | } finally { |
| 6704 | Binder.restoreCallingIdentity(identity); |
| 6705 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6706 | } |
| 6707 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6708 | /** |
| 6709 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6710 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6711 | * @param callback A callback with an integer containing the |
| 6712 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6713 | */ |
| 6714 | @Override |
| 6715 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6716 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6717 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6718 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6719 | "IMS not available on device."); |
| 6720 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6721 | final long token = Binder.clearCallingIdentity(); |
| 6722 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6723 | int slotId = getSlotIndex(subId); |
| 6724 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6725 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6726 | + subId + "'"); |
| 6727 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6728 | } |
| 6729 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6730 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6731 | try { |
| 6732 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6733 | } catch (RemoteException e) { |
| 6734 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6735 | + "Ignore"); |
| 6736 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6737 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6738 | } catch (ImsException e) { |
| 6739 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6740 | } finally { |
| 6741 | Binder.restoreCallingIdentity(token); |
| 6742 | } |
| 6743 | } |
| 6744 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6745 | /** |
| 6746 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6747 | */ |
| 6748 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6749 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6750 | |
| 6751 | final long identity = Binder.clearCallingIdentity(); |
| 6752 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6753 | // NOTE: Before S, this method only set the default phone. |
| 6754 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6755 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6756 | phone.setImsRegistrationState(registered); |
| 6757 | } |
| 6758 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | } finally { |
| 6760 | Binder.restoreCallingIdentity(identity); |
| 6761 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6762 | } |
| 6763 | |
| 6764 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6765 | * Set the network selection mode to automatic. |
| 6766 | * |
| 6767 | */ |
| 6768 | @Override |
| 6769 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6771 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6773 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6774 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6775 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | final long identity = Binder.clearCallingIdentity(); |
| 6777 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6778 | if (!isActiveSubscription(subId)) { |
| 6779 | return; |
| 6780 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6781 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6782 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6783 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6784 | } finally { |
| 6785 | Binder.restoreCallingIdentity(identity); |
| 6786 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6787 | } |
| 6788 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6789 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6790 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6791 | * |
| 6792 | * @param subId the id of the subscription. |
| 6793 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6794 | * the operator to attach to. |
| 6795 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6796 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6797 | * normal network selection next time. |
| 6798 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6799 | */ |
| 6800 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6801 | public boolean setNetworkSelectionModeManual( |
| 6802 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6803 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6804 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6805 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6806 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6807 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6808 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6809 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6810 | if (!isActiveSubscription(subId)) { |
| 6811 | return false; |
| 6812 | } |
| 6813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6814 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6815 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6816 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6817 | if (DBG) { |
| 6818 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6819 | + " operator: " + operatorInfo); |
| 6820 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6821 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6822 | } finally { |
| 6823 | Binder.restoreCallingIdentity(identity); |
| 6824 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6825 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6826 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6827 | * Get the manual network selection |
| 6828 | * |
| 6829 | * @param subId the id of the subscription. |
| 6830 | * |
| 6831 | * @return the previously saved user selected PLMN |
| 6832 | */ |
| 6833 | @Override |
| 6834 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6835 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6836 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6837 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6838 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6839 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6840 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6841 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6842 | final long identity = Binder.clearCallingIdentity(); |
| 6843 | try { |
| 6844 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6845 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6846 | } |
| 6847 | |
| 6848 | final Phone phone = getPhone(subId); |
| 6849 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6850 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6851 | } |
| 6852 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6853 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6854 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6855 | } finally { |
| 6856 | Binder.restoreCallingIdentity(identity); |
| 6857 | } |
| 6858 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6859 | |
| 6860 | /** |
| 6861 | * Scans for available networks. |
| 6862 | */ |
| 6863 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6864 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6865 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6867 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6868 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6869 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6870 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6871 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6872 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6873 | .setCallingPid(Binder.getCallingPid()) |
| 6874 | .setCallingUid(Binder.getCallingUid()) |
| 6875 | .setMethod("getCellNetworkScanResults") |
| 6876 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6877 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6878 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6879 | .build()); |
| 6880 | switch (locationResult) { |
| 6881 | case DENIED_HARD: |
| 6882 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6883 | case DENIED_SOFT: |
| 6884 | return null; |
| 6885 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6886 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6887 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6888 | try { |
| 6889 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6890 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6891 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6892 | } finally { |
| 6893 | Binder.restoreCallingIdentity(identity); |
| 6894 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6898 | * Get the call forwarding info, given the call forwarding reason. |
| 6899 | */ |
| 6900 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6901 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6902 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6903 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6904 | |
| 6905 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6906 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6907 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6908 | long identity = Binder.clearCallingIdentity(); |
| 6909 | try { |
| 6910 | if (DBG) { |
| 6911 | log("getCallForwarding: subId " + subId |
| 6912 | + " callForwardingReason" + callForwardingReason); |
| 6913 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6914 | |
| 6915 | Phone phone = getPhone(subId); |
| 6916 | if (phone == null) { |
| 6917 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6918 | callback.onError( |
| 6919 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6920 | } catch (RemoteException e) { |
| 6921 | // ignore |
| 6922 | } |
| 6923 | return; |
| 6924 | } |
| 6925 | |
| 6926 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6927 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6928 | @Override |
| 6929 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6930 | try { |
| 6931 | callback.onCallForwardingInfoAvailable(info); |
| 6932 | } catch (RemoteException e) { |
| 6933 | // ignore |
| 6934 | } |
| 6935 | } |
| 6936 | |
| 6937 | @Override |
| 6938 | public void onError(int error) { |
| 6939 | try { |
| 6940 | callback.onError(error); |
| 6941 | } catch (RemoteException e) { |
| 6942 | // ignore |
| 6943 | } |
| 6944 | } |
| 6945 | }); |
| 6946 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6947 | } finally { |
| 6948 | Binder.restoreCallingIdentity(identity); |
| 6949 | } |
| 6950 | } |
| 6951 | |
| 6952 | /** |
| 6953 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6954 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6955 | */ |
| 6956 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6957 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6958 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6959 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6960 | |
| 6961 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6962 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6963 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6964 | long identity = Binder.clearCallingIdentity(); |
| 6965 | try { |
| 6966 | if (DBG) { |
| 6967 | log("setCallForwarding: subId " + subId |
| 6968 | + " callForwardingInfo" + callForwardingInfo); |
| 6969 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6970 | |
| 6971 | Phone phone = getPhone(subId); |
| 6972 | if (phone == null) { |
| 6973 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6974 | callback.accept( |
| 6975 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6976 | } catch (RemoteException e) { |
| 6977 | // ignore |
| 6978 | } |
| 6979 | return; |
| 6980 | } |
| 6981 | |
| 6982 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6983 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6984 | |
| 6985 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6986 | } finally { |
| 6987 | Binder.restoreCallingIdentity(identity); |
| 6988 | } |
| 6989 | } |
| 6990 | |
| 6991 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6992 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6993 | */ |
| 6994 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6995 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6996 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6997 | |
| 6998 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6999 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7000 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7001 | long identity = Binder.clearCallingIdentity(); |
| 7002 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7003 | Phone phone = getPhone(subId); |
| 7004 | if (phone == null) { |
| 7005 | try { |
| 7006 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7007 | } catch (RemoteException e) { |
| 7008 | // ignore |
| 7009 | } |
| 7010 | return; |
| 7011 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7012 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7013 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7014 | boolean requireUssd = c.getBoolean( |
| 7015 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7016 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7017 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7018 | if (requireUssd) { |
| 7019 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7020 | getSubscriptionCarrierId(subId)); |
| 7021 | String newUssdCommand = ""; |
| 7022 | try { |
| 7023 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7024 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7025 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7026 | } catch (NullPointerException e) { |
| 7027 | loge("Failed to generate USSD number" + e); |
| 7028 | } |
| 7029 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7030 | mMainThreadHandler, callback, carrierXmlParser, |
| 7031 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7032 | final String ussdCommand = newUssdCommand; |
| 7033 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7034 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7035 | }); |
| 7036 | } else { |
| 7037 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7038 | callback::accept); |
| 7039 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7040 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7041 | } finally { |
| 7042 | Binder.restoreCallingIdentity(identity); |
| 7043 | } |
| 7044 | } |
| 7045 | |
| 7046 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7047 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7048 | */ |
| 7049 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7050 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7051 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7052 | |
| 7053 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7054 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7055 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7056 | long identity = Binder.clearCallingIdentity(); |
| 7057 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7058 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7059 | |
| 7060 | Phone phone = getPhone(subId); |
| 7061 | if (phone == null) { |
| 7062 | try { |
| 7063 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7064 | } catch (RemoteException e) { |
| 7065 | // ignore |
| 7066 | } |
| 7067 | return; |
| 7068 | } |
| 7069 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7070 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7071 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7072 | boolean requireUssd = c.getBoolean( |
| 7073 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7074 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7075 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7076 | if (requireUssd) { |
| 7077 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7078 | getSubscriptionCarrierId(subId)); |
| 7079 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7080 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7081 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7082 | String newUssdCommand = ""; |
| 7083 | try { |
| 7084 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7085 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7086 | .makeCommand(ssAction, null); |
| 7087 | } catch (NullPointerException e) { |
| 7088 | loge("Failed to generate USSD number" + e); |
| 7089 | } |
| 7090 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7091 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7092 | final String ussdCommand = newUssdCommand; |
| 7093 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7094 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7095 | }); |
| 7096 | } else { |
| 7097 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7098 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7099 | |
| 7100 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7101 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7102 | } finally { |
| 7103 | Binder.restoreCallingIdentity(identity); |
| 7104 | } |
| 7105 | } |
| 7106 | |
| 7107 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7108 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7109 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7110 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7111 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7112 | * location related information which will be sent if the caller already possess |
| 7113 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7114 | * @param request contains the radio access networks with bands/channels to scan |
| 7115 | * @param messenger callback messenger for scan results or errors |
| 7116 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7117 | * @return the id of the requested scan which can be used to stop the scan. |
| 7118 | */ |
| 7119 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7120 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7121 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7122 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7124 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7125 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7126 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7127 | if (!renounceFineLocationAccess) { |
| 7128 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7129 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7130 | .setCallingPackage(callingPackage) |
| 7131 | .setCallingFeatureId(callingFeatureId) |
| 7132 | .setCallingPid(Binder.getCallingPid()) |
| 7133 | .setCallingUid(Binder.getCallingUid()) |
| 7134 | .setMethod("requestNetworkScan") |
| 7135 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7136 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7137 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7138 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7139 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7140 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7141 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7142 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7143 | if (e != null) { |
| 7144 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7145 | throw e; |
| 7146 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7147 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7148 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7149 | } |
| 7150 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7151 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7152 | |
| 7153 | enforceTelephonyFeatureWithException(callingPackage, |
| 7154 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7155 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7156 | int callingUid = Binder.getCallingUid(); |
| 7157 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7158 | final long identity = Binder.clearCallingIdentity(); |
| 7159 | try { |
| 7160 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7161 | renounceFineLocationAccess, request, messenger, binder, |
| 7162 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7163 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7164 | } finally { |
| 7165 | Binder.restoreCallingIdentity(identity); |
| 7166 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7167 | } |
| 7168 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7169 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7170 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7171 | boolean hasCarrierPriv; |
| 7172 | final long identity = Binder.clearCallingIdentity(); |
| 7173 | try { |
| 7174 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7175 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7176 | } finally { |
| 7177 | Binder.restoreCallingIdentity(identity); |
| 7178 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7179 | boolean hasNetworkScanPermission = |
| 7180 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7181 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7182 | |
| 7183 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7184 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7185 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7189 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7190 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7191 | return new SecurityException("Specific channels must not be" |
| 7192 | + " scanned without location access."); |
| 7193 | } |
| 7194 | } |
| 7195 | } |
| 7196 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7197 | return null; |
| 7198 | } |
| 7199 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7200 | /** |
| 7201 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7202 | * |
| 7203 | * @param subId id of the subscription |
| 7204 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7205 | */ |
| 7206 | @Override |
| 7207 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7209 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7211 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7212 | final long identity = Binder.clearCallingIdentity(); |
| 7213 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7214 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7215 | } finally { |
| 7216 | Binder.restoreCallingIdentity(identity); |
| 7217 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7218 | } |
| 7219 | |
| 7220 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7221 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7222 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7223 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7224 | */ |
| 7225 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7226 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7227 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7228 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7229 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7230 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7231 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7232 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7233 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | final long identity = Binder.clearCallingIdentity(); |
| 7235 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7236 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7237 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7238 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7239 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7240 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
| 7243 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7244 | } |
| 7245 | |
| 7246 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7247 | * Get the allowed network types for certain reason. |
| 7248 | * |
| 7249 | * @param subId the id of the subscription. |
| 7250 | * @param reason the reason the allowed network type change is taking place |
| 7251 | * @return the allowed network types. |
| 7252 | */ |
| 7253 | @Override |
| 7254 | public long getAllowedNetworkTypesForReason(int subId, |
| 7255 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7256 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7257 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7258 | |
| 7259 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7260 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7261 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7262 | final long identity = Binder.clearCallingIdentity(); |
| 7263 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7264 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7265 | } finally { |
| 7266 | Binder.restoreCallingIdentity(identity); |
| 7267 | } |
| 7268 | } |
| 7269 | |
| 7270 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7271 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7272 | * @param subId subscription id of the sim card |
| 7273 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7274 | * This can be passed following states |
| 7275 | * <ol> |
| 7276 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7277 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7278 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7279 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7280 | * </ol> |
| 7281 | * @return operation result. |
| 7282 | */ |
| 7283 | @Override |
| 7284 | public int setNrDualConnectivityState(int subId, |
| 7285 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7287 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7288 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7289 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7290 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7291 | } |
| 7292 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7293 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7294 | final long identity = Binder.clearCallingIdentity(); |
| 7295 | try { |
| 7296 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7297 | nrDualConnectivityState, subId, |
| 7298 | workSource); |
| 7299 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7300 | return result; |
| 7301 | } finally { |
| 7302 | Binder.restoreCallingIdentity(identity); |
| 7303 | } |
| 7304 | } |
| 7305 | |
| 7306 | /** |
| 7307 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7308 | * @return true if dual connectivity is enabled else false |
| 7309 | */ |
| 7310 | @Override |
| 7311 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7312 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7313 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7314 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7315 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7316 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7317 | return false; |
| 7318 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7319 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7320 | final long identity = Binder.clearCallingIdentity(); |
| 7321 | try { |
| 7322 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7323 | null, subId, workSource); |
| 7324 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7325 | return isEnabled; |
| 7326 | } finally { |
| 7327 | Binder.restoreCallingIdentity(identity); |
| 7328 | } |
| 7329 | } |
| 7330 | |
| 7331 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7332 | * Set the allowed network types of the device and |
| 7333 | * provide the reason triggering the allowed network change. |
| 7334 | * |
| 7335 | * @param subId the id of the subscription. |
| 7336 | * @param reason the reason the allowed network type change is taking place |
| 7337 | * @param allowedNetworkTypes the allowed network types. |
| 7338 | * @return true on success; false on any failure. |
| 7339 | */ |
| 7340 | @Override |
| 7341 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7342 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7343 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7345 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7346 | // If the caller only has carrier privileges, then they should not be able to override |
| 7347 | // any network types which were set for security reasons. |
| 7348 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7349 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7350 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7351 | throw new SecurityException( |
| 7352 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7353 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7354 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7355 | |
| 7356 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7357 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7358 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7359 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7360 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7361 | return false; |
| 7362 | } |
| 7363 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7364 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7365 | return false; |
| 7366 | } |
| 7367 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7368 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7369 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7370 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7371 | Phone phone = getPhone(subId); |
| 7372 | if (phone == null) { |
| 7373 | return false; |
| 7374 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7375 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7376 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7377 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7378 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7379 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7380 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7381 | final long identity = Binder.clearCallingIdentity(); |
| 7382 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7383 | Boolean success = (Boolean) sendRequest( |
| 7384 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7385 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7386 | |
| 7387 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7388 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7389 | } finally { |
| 7390 | Binder.restoreCallingIdentity(identity); |
| 7391 | } |
| 7392 | } |
| 7393 | |
| 7394 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7395 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7396 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7397 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7398 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7399 | * @hide |
| 7400 | */ |
| 7401 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7402 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7403 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7404 | |
| 7405 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7406 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7407 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7408 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7409 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7410 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7411 | if (phone != null) { |
| 7412 | return phone.hasMatchedTetherApnSetting(); |
| 7413 | } else { |
| 7414 | return false; |
| 7415 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7416 | } finally { |
| 7417 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7418 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7422 | * Get the user enabled state of Mobile Data. |
| 7423 | * |
| 7424 | * TODO: remove and use isUserDataEnabled. |
| 7425 | * This can't be removed now because some vendor codes |
| 7426 | * calls through ITelephony directly while they should |
| 7427 | * use TelephonyManager. |
| 7428 | * |
| 7429 | * @return true on enabled |
| 7430 | */ |
| 7431 | @Override |
| 7432 | public boolean getDataEnabled(int subId) { |
| 7433 | return isUserDataEnabled(subId); |
| 7434 | } |
| 7435 | |
| 7436 | /** |
| 7437 | * Get whether mobile data is enabled per user setting. |
| 7438 | * |
| 7439 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7440 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7441 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7442 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7443 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7444 | * |
| 7445 | * @return {@code true} if data is enabled else {@code false} |
| 7446 | */ |
| 7447 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7448 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7449 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7450 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7451 | try { |
| 7452 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7453 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7454 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7455 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7456 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7457 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7458 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7459 | mApp, subId, functionName); |
| 7460 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7461 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7462 | |
| 7463 | final long identity = Binder.clearCallingIdentity(); |
| 7464 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7465 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7466 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7467 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7468 | if (phone != null) { |
| 7469 | boolean retVal = phone.isUserDataEnabled(); |
| 7470 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7471 | return retVal; |
| 7472 | } else { |
| 7473 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7474 | return false; |
| 7475 | } |
| 7476 | } finally { |
| 7477 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7478 | } |
| 7479 | } |
| 7480 | |
| 7481 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7482 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7483 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7484 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7485 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7486 | * @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] | 7487 | */ |
| 7488 | @Override |
| 7489 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7490 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7491 | try { |
| 7492 | try { |
| 7493 | mApp.enforceCallingOrSelfPermission( |
| 7494 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7495 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7496 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7497 | try { |
| 7498 | mApp.enforceCallingOrSelfPermission( |
| 7499 | android.Manifest.permission.READ_PHONE_STATE, |
| 7500 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7501 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7502 | mApp.enforceCallingOrSelfPermission( |
| 7503 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7504 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7505 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7506 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7507 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7508 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7509 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7510 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7511 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7512 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7513 | final long identity = Binder.clearCallingIdentity(); |
| 7514 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7515 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7516 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7517 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7518 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7519 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7520 | return retVal; |
| 7521 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7522 | if (DBG) { |
| 7523 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7524 | + subId + " retVal=false"); |
| 7525 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | return false; |
| 7527 | } |
| 7528 | } finally { |
| 7529 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7530 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7531 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7532 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7533 | /** |
| 7534 | * Check if data is enabled for a specific reason |
| 7535 | * @param subId Subscription index |
| 7536 | * @param reason the reason the data enable change is taking place |
| 7537 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7538 | */ |
| 7539 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7540 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7541 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7542 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7543 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7544 | try { |
| 7545 | mApp.enforceCallingOrSelfPermission( |
| 7546 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7547 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7548 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7549 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7550 | functionName); |
| 7551 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7552 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7553 | try { |
| 7554 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7555 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7556 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7558 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7559 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7560 | } |
| 7561 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7562 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7563 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7564 | |
| 7565 | final long identity = Binder.clearCallingIdentity(); |
| 7566 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7567 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7568 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7569 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7570 | + " reason=" + reason); |
| 7571 | } |
| 7572 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7573 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7574 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7575 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7576 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7577 | return retVal; |
| 7578 | } else { |
| 7579 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7580 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7581 | + subId + " retVal=false"); |
| 7582 | } |
| 7583 | return false; |
| 7584 | } |
| 7585 | } finally { |
| 7586 | Binder.restoreCallingIdentity(identity); |
| 7587 | } |
| 7588 | } |
| 7589 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7590 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7591 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7592 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7593 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7594 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7595 | // No permission needed; this only lets the caller inspect their own status. |
| 7596 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7597 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7598 | |
| 7599 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7600 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7601 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7602 | |
| 7603 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7604 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7605 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7606 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7607 | } |
| 7608 | |
| 7609 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7610 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7611 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7612 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7613 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7614 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7615 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7616 | if (cpt == null) { |
| 7617 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7618 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7619 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7620 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7621 | } |
| 7622 | |
| 7623 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7624 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7625 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7626 | |
| 7627 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7628 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7629 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7630 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7631 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7632 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7633 | Phone phone = getPhone(subId); |
| 7634 | if (phone == null) { |
| 7635 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7636 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7637 | } |
| 7638 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7639 | if (cpt == null) { |
| 7640 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7641 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7642 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7643 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7644 | } |
| 7645 | |
| 7646 | @Override |
| 7647 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7648 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7649 | |
| 7650 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7651 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7652 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7653 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7654 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7655 | } |
| 7656 | |
| 7657 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7658 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7659 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7660 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7661 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7662 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7663 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7664 | if (phone == null) { |
| 7665 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7666 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7667 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7668 | if (cpt == null) { |
| 7669 | continue; |
| 7670 | } |
| 7671 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7672 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7673 | break; |
| 7674 | } |
| 7675 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7676 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7677 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7678 | |
| 7679 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7680 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7681 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7682 | |
| 7683 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7684 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7685 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7686 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7687 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7688 | if (phone == null) { |
| 7689 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7690 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7691 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7692 | if (cpt == null) { |
| 7693 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7694 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7695 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7696 | } |
| 7697 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7698 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7699 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7700 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7701 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7702 | if (phone == null) { |
| 7703 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7704 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7705 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7706 | if (cpt == null) { |
| 7707 | return Collections.emptyList(); |
| 7708 | } |
| 7709 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7710 | } |
| 7711 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7712 | @Override |
| 7713 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7714 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7715 | |
| 7716 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7717 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7718 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7719 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7720 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7721 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7722 | try { |
| 7723 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7724 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7725 | } |
| 7726 | } finally { |
| 7727 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7728 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7729 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7730 | } |
| 7731 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7732 | @Override |
| 7733 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7734 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7735 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7736 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7737 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7738 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7739 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7740 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7741 | if (phone == null) { |
| 7742 | return null; |
| 7743 | } |
| 7744 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7745 | if (cpt == null) { |
| 7746 | return null; |
| 7747 | } |
| 7748 | return cpt.getCarrierServicePackageName(); |
| 7749 | } |
| 7750 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7751 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7752 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7753 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7754 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7755 | return null; |
| 7756 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7757 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7758 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7759 | return null; |
| 7760 | } |
| 7761 | return iccId; |
| 7762 | } |
| 7763 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7764 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7765 | public void setCallComposerStatus(int subId, int status) { |
| 7766 | enforceModifyPermission(); |
| 7767 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7768 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7769 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7770 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7771 | final long identity = Binder.clearCallingIdentity(); |
| 7772 | try { |
| 7773 | Phone phone = getPhone(subId); |
| 7774 | if (phone != null) { |
| 7775 | Phone defaultPhone = phone.getImsPhone(); |
| 7776 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7777 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7778 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7779 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7780 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7781 | } |
| 7782 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7783 | } catch (ImsException e) { |
| 7784 | throw new ServiceSpecificException(e.getCode()); |
| 7785 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7786 | Binder.restoreCallingIdentity(identity); |
| 7787 | } |
| 7788 | } |
| 7789 | |
| 7790 | @Override |
| 7791 | public int getCallComposerStatus(int subId) { |
| 7792 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7793 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7794 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7795 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7796 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7797 | final long identity = Binder.clearCallingIdentity(); |
| 7798 | try { |
| 7799 | Phone phone = getPhone(subId); |
| 7800 | if (phone != null) { |
| 7801 | Phone defaultPhone = phone.getImsPhone(); |
| 7802 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7803 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7804 | return imsPhone.getCallComposerStatus(); |
| 7805 | } |
| 7806 | } |
| 7807 | } finally { |
| 7808 | Binder.restoreCallingIdentity(identity); |
| 7809 | } |
| 7810 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7811 | } |
| 7812 | |
| 7813 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7814 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7815 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7816 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7817 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7818 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7819 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7820 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7821 | "setLine1NumberForDisplayForSubscriber"); |
| 7822 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7823 | final long identity = Binder.clearCallingIdentity(); |
| 7824 | try { |
| 7825 | final String iccId = getIccId(subId); |
| 7826 | final Phone phone = getPhone(subId); |
| 7827 | if (phone == null) { |
| 7828 | return false; |
| 7829 | } |
| 7830 | final String subscriberId = phone.getSubscriberId(); |
| 7831 | |
| 7832 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7833 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7834 | + subscriberId + " to " + number); |
| 7835 | } |
| 7836 | |
| 7837 | if (TextUtils.isEmpty(iccId)) { |
| 7838 | return false; |
| 7839 | } |
| 7840 | |
| 7841 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7842 | |
| 7843 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7844 | if (alphaTag == null) { |
| 7845 | editor.remove(alphaTagPrefKey); |
| 7846 | } else { |
| 7847 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7848 | } |
| 7849 | |
| 7850 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7851 | // track all merged IMSIs based on line number |
| 7852 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7853 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7854 | if (number == null) { |
| 7855 | editor.remove(numberPrefKey); |
| 7856 | editor.remove(subscriberPrefKey); |
| 7857 | } else { |
| 7858 | editor.putString(numberPrefKey, number); |
| 7859 | editor.putString(subscriberPrefKey, subscriberId); |
| 7860 | } |
| 7861 | |
| 7862 | editor.commit(); |
| 7863 | return true; |
| 7864 | } finally { |
| 7865 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7866 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7867 | } |
| 7868 | |
| 7869 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7870 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7871 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7872 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7873 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7874 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7875 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7876 | return null; |
| 7877 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7878 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7879 | enforceTelephonyFeatureWithException(callingPackage, |
| 7880 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7882 | final long identity = Binder.clearCallingIdentity(); |
| 7883 | try { |
| 7884 | String iccId = getIccId(subId); |
| 7885 | if (iccId != null) { |
| 7886 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7887 | if (DBG_MERGE) { |
| 7888 | log("getLine1NumberForDisplay returning " |
| 7889 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7890 | } |
| 7891 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7892 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7893 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7894 | return null; |
| 7895 | } finally { |
| 7896 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7897 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7901 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7902 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7903 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7904 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7905 | return null; |
| 7906 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7908 | final long identity = Binder.clearCallingIdentity(); |
| 7909 | try { |
| 7910 | String iccId = getIccId(subId); |
| 7911 | if (iccId != null) { |
| 7912 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7913 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7914 | } |
| 7915 | return null; |
| 7916 | } finally { |
| 7917 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7918 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7919 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7920 | |
| 7921 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7922 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7923 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7924 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7925 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7927 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7928 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7929 | return null; |
| 7930 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7931 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7932 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7933 | // the process, where TelephonyManager was instantiated. |
| 7934 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7935 | final long identity = Binder.clearCallingIdentity(); |
| 7936 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7937 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7938 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7939 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7940 | |
| 7941 | // Figure out what subscribers are currently active |
| 7942 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7943 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7944 | // Only consider subs which match the current subId |
| 7945 | // This logic can be simplified. See b/131189269 for progress. |
| 7946 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7947 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7948 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7949 | |
| 7950 | // First pass, find a number override for an active subscriber |
| 7951 | String mergeNumber = null; |
| 7952 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7953 | for (String key : prefs.keySet()) { |
| 7954 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7955 | final String subscriberId = (String) prefs.get(key); |
| 7956 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7957 | final String iccId = key.substring( |
| 7958 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7959 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7960 | mergeNumber = (String) prefs.get(numberKey); |
| 7961 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7962 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7963 | + " for active subscriber " + subscriberId); |
| 7964 | } |
| 7965 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7966 | break; |
| 7967 | } |
| 7968 | } |
| 7969 | } |
| 7970 | } |
| 7971 | |
| 7972 | // Shortcut when no active merged subscribers |
| 7973 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7974 | return null; |
| 7975 | } |
| 7976 | |
| 7977 | // Second pass, find all subscribers under that line override |
| 7978 | final ArraySet<String> result = new ArraySet<>(); |
| 7979 | for (String key : prefs.keySet()) { |
| 7980 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7981 | final String number = (String) prefs.get(key); |
| 7982 | if (mergeNumber.equals(number)) { |
| 7983 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7984 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7985 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7986 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7987 | result.add(subscriberId); |
| 7988 | } |
| 7989 | } |
| 7990 | } |
| 7991 | } |
| 7992 | |
| 7993 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7994 | Arrays.sort(resultArray); |
| 7995 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7996 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7997 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7998 | } |
| 7999 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8000 | } finally { |
| 8001 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8002 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8006 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8007 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8008 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8009 | enforceTelephonyFeatureWithException(callingPackage, |
| 8010 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8011 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8012 | final long identity = Binder.clearCallingIdentity(); |
| 8013 | try { |
| 8014 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8015 | TelephonyManager.class); |
| 8016 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8017 | if (subscriberId == null) { |
| 8018 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8019 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8020 | + subId); |
| 8021 | } |
| 8022 | return null; |
| 8023 | } |
| 8024 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8025 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8026 | .getSubscriptionInfo(subId); |
| 8027 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8028 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8029 | if (groupUuid == null) { |
| 8030 | return new String[]{subscriberId}; |
| 8031 | } |
| 8032 | |
| 8033 | // Get all subscriberIds from the group. |
| 8034 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8035 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8036 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8037 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8038 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8039 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8040 | if (subscriberId != null) { |
| 8041 | mergedSubscriberIds.add(subscriberId); |
| 8042 | } |
| 8043 | } |
| 8044 | |
| 8045 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8046 | } finally { |
| 8047 | Binder.restoreCallingIdentity(identity); |
| 8048 | |
| 8049 | } |
| 8050 | } |
| 8051 | |
| 8052 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8053 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8054 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8055 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8056 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8057 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8058 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8059 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8060 | final long identity = Binder.clearCallingIdentity(); |
| 8061 | try { |
| 8062 | final Phone phone = getPhone(subId); |
| 8063 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8064 | } finally { |
| 8065 | Binder.restoreCallingIdentity(identity); |
| 8066 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8067 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8068 | |
| 8069 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8070 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8071 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8072 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8073 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8074 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8075 | |
| 8076 | final long identity = Binder.clearCallingIdentity(); |
| 8077 | try { |
| 8078 | final Phone phone = getPhone(subId); |
| 8079 | if (phone == null) { |
| 8080 | return false; |
| 8081 | } |
| 8082 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8083 | cdmaNonRoamingList); |
| 8084 | } finally { |
| 8085 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8086 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8087 | } |
| 8088 | |
| 8089 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8090 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8091 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8092 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8093 | if (phone == null) { |
| 8094 | return raf; |
| 8095 | } |
| 8096 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8097 | try { |
| 8098 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8099 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8100 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8101 | } catch (SecurityException e) { |
| 8102 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8103 | throw e; |
| 8104 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8105 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8106 | enforceTelephonyFeatureWithException(callingPackage, |
| 8107 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8108 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8109 | final long identity = Binder.clearCallingIdentity(); |
| 8110 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8111 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8112 | } finally { |
| 8113 | Binder.restoreCallingIdentity(identity); |
| 8114 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8115 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8116 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8117 | |
| 8118 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8119 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8120 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8121 | try { |
| 8122 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8123 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8124 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8125 | } |
| 8126 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8127 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8128 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8129 | |
| 8130 | enforceTelephonyFeatureWithException(callingPackage, |
| 8131 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8132 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8133 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8134 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8135 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8136 | throw new SecurityException("App must be the dialer role holder to" |
| 8137 | + " upload a call composer pic"); |
| 8138 | } |
| 8139 | |
| 8140 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8141 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8142 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8143 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8144 | boolean readUntilEnd = false; |
| 8145 | int totalBytesRead = 0; |
| 8146 | byte[] buffer = new byte[16 * 1024]; |
| 8147 | while (true) { |
| 8148 | int numRead; |
| 8149 | try { |
| 8150 | numRead = input.read(buffer); |
| 8151 | } catch (IOException e) { |
| 8152 | try { |
| 8153 | fd.checkError(); |
| 8154 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8155 | null); |
| 8156 | } catch (IOException e1) { |
| 8157 | // This means that the other side closed explicitly with an error. If this |
| 8158 | // happens, log and ignore. |
| 8159 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8160 | } |
| 8161 | break; |
| 8162 | } |
| 8163 | if (numRead == -1) { |
| 8164 | readUntilEnd = true; |
| 8165 | break; |
| 8166 | } |
| 8167 | totalBytesRead += numRead; |
| 8168 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8169 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8170 | try { |
| 8171 | input.close(); |
| 8172 | } catch (IOException e) { |
| 8173 | // ignore |
| 8174 | } |
| 8175 | break; |
| 8176 | } |
| 8177 | output.write(buffer, 0, numRead); |
| 8178 | } |
| 8179 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8180 | // close is above, where the picture size is too big. |
| 8181 | |
| 8182 | try { |
| 8183 | fd.checkError(); |
| 8184 | } catch (IOException e) { |
| 8185 | loge("Remote end for call composer closed with an error: " + e); |
| 8186 | return; |
| 8187 | } |
| 8188 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8189 | if (!readUntilEnd) { |
| 8190 | loge("Did not finish reading entire image; aborting"); |
| 8191 | return; |
| 8192 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8193 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8194 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8195 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8196 | new CallComposerPictureTransfer.Factory() {}, |
| 8197 | imageData, |
| 8198 | (result) -> { |
| 8199 | if (result.first != null) { |
| 8200 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8201 | Bundle outputResult = new Bundle(); |
| 8202 | outputResult.putParcelable( |
| 8203 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8204 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8205 | outputResult); |
| 8206 | } else { |
| 8207 | callback.send(result.second, null); |
| 8208 | } |
| 8209 | } |
| 8210 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8211 | }); |
| 8212 | } |
| 8213 | |
| 8214 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8215 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8216 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8217 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8218 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8219 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8220 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8222 | final long identity = Binder.clearCallingIdentity(); |
| 8223 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8224 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8225 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8226 | } finally { |
| 8227 | Binder.restoreCallingIdentity(identity); |
| 8228 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8229 | } |
| 8230 | |
| 8231 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8232 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8233 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8234 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8235 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8236 | return false; |
| 8237 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8238 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8239 | enforceTelephonyFeatureWithException(callingPackage, |
| 8240 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8242 | final long identity = Binder.clearCallingIdentity(); |
| 8243 | try { |
| 8244 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8245 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8246 | // In the long run, we may instead need to check if there exists a connection service |
| 8247 | // which can support video calling. |
| 8248 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8249 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8250 | return imsManager.isVtEnabledByPlatform() |
| 8251 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8252 | && imsManager.isVtEnabledByUser(); |
| 8253 | } finally { |
| 8254 | Binder.restoreCallingIdentity(identity); |
| 8255 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8256 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8257 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8258 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8259 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8260 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8261 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8262 | mApp, subId, callingPackage, callingFeatureId, |
| 8263 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8264 | return false; |
| 8265 | } |
| 8266 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8267 | enforceTelephonyFeatureWithException(callingPackage, |
| 8268 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8270 | final long identity = Binder.clearCallingIdentity(); |
| 8271 | try { |
| 8272 | CarrierConfigManager configManager = |
| 8273 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8274 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8275 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8276 | } finally { |
| 8277 | Binder.restoreCallingIdentity(identity); |
| 8278 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8282 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8283 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8284 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8285 | return false; |
| 8286 | } |
| 8287 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8288 | enforceTelephonyFeatureWithException(callingPackage, |
| 8289 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8290 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | final long identity = Binder.clearCallingIdentity(); |
| 8292 | try { |
| 8293 | CarrierConfigManager configManager = |
| 8294 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8295 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8296 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8297 | } finally { |
| 8298 | Binder.restoreCallingIdentity(identity); |
| 8299 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8300 | } |
| 8301 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8302 | @Override |
| 8303 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8304 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8305 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8306 | } |
| 8307 | |
| 8308 | @Override |
| 8309 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8310 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8311 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | final long identity = Binder.clearCallingIdentity(); |
| 8314 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8315 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8316 | } finally { |
| 8317 | Binder.restoreCallingIdentity(identity); |
| 8318 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8319 | } |
| 8320 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8321 | /** |
| 8322 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8323 | * support for the feature and device firmware support. |
| 8324 | * |
| 8325 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8326 | */ |
| 8327 | @Override |
| 8328 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8329 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8330 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8331 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8332 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8333 | final Phone phone = getPhone(subscriptionId); |
| 8334 | if (phone == null) { |
| 8335 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8336 | return false; |
| 8337 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8339 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8340 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8341 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8342 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8343 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8344 | return isCarrierSupported && isDeviceSupported; |
| 8345 | } finally { |
| 8346 | Binder.restoreCallingIdentity(identity); |
| 8347 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8348 | } |
| 8349 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8350 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8351 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8352 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8353 | * 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] | 8354 | */ |
| 8355 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8356 | final long identity = Binder.clearCallingIdentity(); |
| 8357 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8358 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8359 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8360 | return false; |
| 8361 | } |
| 8362 | } |
| 8363 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8364 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8365 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8366 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8367 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8368 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8369 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8370 | } finally { |
| 8371 | Binder.restoreCallingIdentity(identity); |
| 8372 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8373 | } |
| 8374 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8375 | @Deprecated |
| 8376 | @Override |
| 8377 | public String getDeviceId(String callingPackage) { |
| 8378 | return getDeviceIdWithFeature(callingPackage, null); |
| 8379 | } |
| 8380 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8381 | /** |
| 8382 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8383 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8384 | * |
| 8385 | * <p>Requires Permission: |
| 8386 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8387 | */ |
| 8388 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8389 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8390 | try { |
| 8391 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8392 | } catch (SecurityException se) { |
| 8393 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8394 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8395 | + Binder.getCallingUid()); |
| 8396 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8397 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8398 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8399 | return null; |
| 8400 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8401 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8402 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8403 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8404 | return null; |
| 8405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8406 | |
| 8407 | final long identity = Binder.clearCallingIdentity(); |
| 8408 | try { |
| 8409 | return phone.getDeviceId(); |
| 8410 | } finally { |
| 8411 | Binder.restoreCallingIdentity(identity); |
| 8412 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8413 | } |
| 8414 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8415 | /** |
| 8416 | * {@hide} |
| 8417 | * Returns the IMS Registration Status on a particular subid |
| 8418 | * |
| 8419 | * @param subId |
| 8420 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8421 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8422 | Phone phone = getPhone(subId); |
| 8423 | if (phone != null) { |
| 8424 | return phone.isImsRegistered(); |
| 8425 | } else { |
| 8426 | return false; |
| 8427 | } |
| 8428 | } |
| 8429 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8430 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8431 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8432 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8433 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8434 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8435 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8436 | } |
| 8437 | final long identity = Binder.clearCallingIdentity(); |
| 8438 | try { |
| 8439 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8440 | } finally { |
| 8441 | Binder.restoreCallingIdentity(identity); |
| 8442 | } |
| 8443 | } |
| 8444 | |
| 8445 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8446 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8447 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8448 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8449 | mApp, |
| 8450 | subscriptionId, |
| 8451 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8452 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8453 | |
| 8454 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8455 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8456 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8457 | final long identity = Binder.clearCallingIdentity(); |
| 8458 | try { |
| 8459 | Phone phone = getPhone(subscriptionId); |
| 8460 | if (phone == null) { |
| 8461 | return null; |
| 8462 | } |
| 8463 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8464 | } finally { |
| 8465 | Binder.restoreCallingIdentity(identity); |
| 8466 | } |
| 8467 | } |
| 8468 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8469 | /** |
| 8470 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8471 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8472 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8473 | final long identity = Binder.clearCallingIdentity(); |
| 8474 | try { |
| 8475 | Phone phone = getPhone(subId); |
| 8476 | if (phone != null) { |
| 8477 | return phone.isWifiCallingEnabled(); |
| 8478 | } else { |
| 8479 | return false; |
| 8480 | } |
| 8481 | } finally { |
| 8482 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8483 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8484 | } |
| 8485 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8486 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8487 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8488 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8489 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | Phone phone = getPhone(subId); |
| 8493 | if (phone != null) { |
| 8494 | return phone.isVideoEnabled(); |
| 8495 | } else { |
| 8496 | return false; |
| 8497 | } |
| 8498 | } finally { |
| 8499 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8500 | } |
| 8501 | } |
| 8502 | |
| 8503 | /** |
| 8504 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8505 | * defined in {@link ImsRegistrationImplBase}. |
| 8506 | */ |
| 8507 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8508 | final long identity = Binder.clearCallingIdentity(); |
| 8509 | try { |
| 8510 | Phone phone = getPhone(subId); |
| 8511 | if (phone != null) { |
| 8512 | return phone.getImsRegistrationTech(); |
| 8513 | } else { |
| 8514 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8515 | } |
| 8516 | } finally { |
| 8517 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8518 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8519 | } |
| 8520 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8521 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8522 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8523 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8524 | |
| 8525 | enforceTelephonyFeatureWithException(callingPackage, |
| 8526 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8527 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8528 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8529 | return; |
| 8530 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8531 | Phone defaultPhone = getDefaultPhone(); |
| 8532 | if (defaultPhone != null) { |
| 8533 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8534 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8535 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8536 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8537 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8538 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8539 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8540 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8541 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8542 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8543 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8544 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8545 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8546 | setDataRoamingEnabled(subId, phone == null ? false |
| 8547 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8548 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8549 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8550 | // There has been issues when Sms raw table somehow stores orphan |
| 8551 | // fragments. They lead to garbled message when new fragments come |
| 8552 | // in and combined with those stale ones. In case this happens again, |
| 8553 | // user can reset all network settings which will clean up this table. |
| 8554 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8555 | // Clean up IMS settings as well here. |
| 8556 | int slotId = getSlotIndex(subId); |
| 8557 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8558 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8559 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8560 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8561 | if (defaultPhone == null) { |
| 8562 | return; |
| 8563 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8564 | // Erase modem config if erase modem on network setting is enabled. |
| 8565 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8566 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8567 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8568 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8569 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8570 | |
| 8571 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8572 | } finally { |
| 8573 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8574 | } |
| 8575 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8576 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8577 | @VisibleForTesting |
| 8578 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8579 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8580 | return; |
| 8581 | } |
| 8582 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8583 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8584 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8585 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8586 | "user=" + defaultNetworkType); |
| 8587 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8588 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8589 | defaultNetworkType, null); |
| 8590 | } |
| 8591 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8592 | private void cleanUpSmsRawTable(Context context) { |
| 8593 | ContentResolver resolver = context.getContentResolver(); |
| 8594 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8595 | resolver.delete(uri, null, null); |
| 8596 | } |
| 8597 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8598 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8599 | public String getSimLocaleForSubscriber(int subId) { |
| 8600 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8601 | |
| 8602 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8603 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8604 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8605 | final Phone phone = getPhone(subId); |
| 8606 | if (phone == null) { |
| 8607 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8608 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8609 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8610 | final long identity = Binder.clearCallingIdentity(); |
| 8611 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8612 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8613 | phone.getContext().getOpPackageName(), |
| 8614 | phone.getContext().getAttributionTag()); |
| 8615 | if (info == null) { |
| 8616 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8617 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8618 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8619 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8620 | // preferences (EF-PL and EF-LI)... |
| 8621 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8622 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8623 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8624 | if (localeFromDefaultSim != null) { |
| 8625 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8626 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8627 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8628 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8629 | } else { |
| 8630 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8631 | } |
| 8632 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8633 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8634 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8635 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8636 | // the SIM and carrier preferences does not include a country we add the country |
| 8637 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8638 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8639 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8640 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8641 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8642 | } |
| 8643 | |
| 8644 | if (DBG) log("No locale found - returning null"); |
| 8645 | return null; |
| 8646 | } finally { |
| 8647 | Binder.restoreCallingIdentity(identity); |
| 8648 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8649 | } |
| 8650 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8651 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8652 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8653 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8654 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8655 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8656 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8657 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8658 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8659 | return localeTag; |
| 8660 | } |
| 8661 | } |
| 8662 | return inputLocale.toLanguageTag(); |
| 8663 | } |
| 8664 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8665 | /** |
| 8666 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8667 | */ |
| 8668 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8669 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8670 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8671 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8672 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8673 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8674 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8675 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8676 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8677 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8678 | * representing the state of the modem. |
| 8679 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8680 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8681 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8682 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8683 | */ |
| 8684 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8685 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8686 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8687 | |
| 8688 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8689 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8690 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8691 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8692 | |
| 8693 | final long identity = Binder.clearCallingIdentity(); |
| 8694 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8695 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8696 | } finally { |
| 8697 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8698 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8699 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8700 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8701 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8702 | // less than total activity duration. |
| 8703 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8704 | if (info == null) { |
| 8705 | return false; |
| 8706 | } |
| 8707 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8708 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8709 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8710 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8711 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8712 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8713 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8714 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8715 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8716 | } |
| 8717 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8718 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8719 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8720 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8721 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8722 | |
| 8723 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8724 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8725 | } |
| 8726 | |
| 8727 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8728 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8729 | rat, |
| 8730 | freq, |
| 8731 | info.getReceiveTimeMillis(rat, freq) |
| 8732 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8733 | } |
| 8734 | |
| 8735 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8736 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8737 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8738 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8739 | |
| 8740 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8741 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8742 | } |
| 8743 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8744 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8745 | rat, |
| 8746 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8747 | } |
| 8748 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8749 | /** |
| 8750 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8751 | * @param info recent ModemActivityInfo |
| 8752 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8753 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8754 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8755 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8756 | boolean matched; |
| 8757 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8758 | matched = false; |
| 8759 | int rat = info.getSpecificInfoRat(i); |
| 8760 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8761 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8762 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8763 | //if it already exists |
| 8764 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8765 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8766 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8767 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8768 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8769 | updateLastModemActivityInfo(info, rat, freq); |
| 8770 | matched = true; |
| 8771 | } |
| 8772 | } else { |
| 8773 | updateLastModemActivityInfo(info, rat); |
| 8774 | matched = true; |
| 8775 | } |
| 8776 | } |
| 8777 | } |
| 8778 | |
| 8779 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8780 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8781 | new ActivityStatsTechSpecificInfo( |
| 8782 | rat, |
| 8783 | freq, |
| 8784 | info.getTransmitTimeMillis(rat, freq), |
| 8785 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8786 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8787 | } |
| 8788 | } |
| 8789 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8790 | mLastModemActivitySpecificInfo = |
| 8791 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8792 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8793 | |
| 8794 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8795 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8796 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8797 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8798 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8799 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8800 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8801 | |
| 8802 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8803 | new ModemActivityInfo( |
| 8804 | mLastModemActivityInfo.getTimestampMillis(), |
| 8805 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8806 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8807 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8808 | } |
| 8809 | |
| 8810 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8811 | ActivityStatsTechSpecificInfo[] info) { |
| 8812 | int infoSize = info.length; |
| 8813 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8814 | for (int i = 0; i < infoSize; i++) { |
| 8815 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8816 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8817 | info[i].getTransmitTimeMillis(), |
| 8818 | (int) info[i].getReceiveTimeMillis()); |
| 8819 | } |
| 8820 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8821 | } |
| 8822 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8823 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8824 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8825 | */ |
| 8826 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8827 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8828 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8829 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8830 | if (phone == null) { |
| 8831 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8832 | return null; |
| 8833 | } |
| 8834 | |
| 8835 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8836 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8837 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8838 | return null; |
| 8839 | } |
| 8840 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8841 | enforceTelephonyFeatureWithException(callingPackage, |
| 8842 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8843 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8844 | boolean hasFinePermission = false; |
| 8845 | boolean hasCoarsePermission = false; |
| 8846 | if (!renounceFineLocationAccess) { |
| 8847 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8848 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8849 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8850 | .setCallingPackage(callingPackage) |
| 8851 | .setCallingFeatureId(callingFeatureId) |
| 8852 | .setCallingPid(Binder.getCallingPid()) |
| 8853 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8854 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8855 | .setLogAsInfo(true) |
| 8856 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8857 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8858 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8859 | .build()); |
| 8860 | hasFinePermission = |
| 8861 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8862 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8863 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8864 | if (!renounceCoarseLocationAccess) { |
| 8865 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8866 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8867 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8868 | .setCallingPackage(callingPackage) |
| 8869 | .setCallingFeatureId(callingFeatureId) |
| 8870 | .setCallingPid(Binder.getCallingPid()) |
| 8871 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8872 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8873 | .setLogAsInfo(true) |
| 8874 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8875 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8876 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8877 | .build()); |
| 8878 | hasCoarsePermission = |
| 8879 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8880 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8881 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8882 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8883 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8884 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8885 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8886 | if (subInfo != null && !subInfo.isActive()) { |
| 8887 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8888 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8889 | } |
| 8890 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8891 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8892 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8893 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8894 | |
| 8895 | // Scrub out the location info in ServiceState depending on what level of access |
| 8896 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8897 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8898 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8899 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8900 | } finally { |
| 8901 | Binder.restoreCallingIdentity(identity); |
| 8902 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8903 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8904 | |
| 8905 | /** |
| 8906 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8907 | * |
| 8908 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8909 | * voicemail ringtone. |
| 8910 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8911 | * PhoneAccount. |
| 8912 | */ |
| 8913 | @Override |
| 8914 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8915 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8916 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8917 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8918 | final long identity = Binder.clearCallingIdentity(); |
| 8919 | try { |
| 8920 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8921 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8922 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8923 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8924 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8925 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8926 | } finally { |
| 8927 | Binder.restoreCallingIdentity(identity); |
| 8928 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8929 | } |
| 8930 | |
| 8931 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8932 | * Sets the per-account voicemail ringtone. |
| 8933 | * |
| 8934 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8935 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8936 | * |
| 8937 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8938 | * voicemail ringtone. |
| 8939 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8940 | * PhoneAccount. |
| 8941 | */ |
| 8942 | @Override |
| 8943 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8944 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8945 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8946 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8947 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8948 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8950 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8951 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8952 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8953 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8954 | enforceTelephonyFeatureWithException(callingPackage, |
| 8955 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8956 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8957 | final long identity = Binder.clearCallingIdentity(); |
| 8958 | try { |
| 8959 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8960 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8961 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8962 | } |
| 8963 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8964 | } finally { |
| 8965 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8966 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8967 | } |
| 8968 | |
| 8969 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8970 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8971 | * |
| 8972 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8973 | * voicemail vibration setting. |
| 8974 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8975 | */ |
| 8976 | @Override |
| 8977 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8978 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8979 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8980 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8981 | final long identity = Binder.clearCallingIdentity(); |
| 8982 | try { |
| 8983 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8984 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8985 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8986 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8987 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8988 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8989 | } finally { |
| 8990 | Binder.restoreCallingIdentity(identity); |
| 8991 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8992 | } |
| 8993 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8994 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8995 | * Sets the per-account voicemail vibration. |
| 8996 | * |
| 8997 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8998 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8999 | * |
| 9000 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9001 | * voicemail vibration setting. |
| 9002 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9003 | * specific PhoneAccount. |
| 9004 | */ |
| 9005 | @Override |
| 9006 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9007 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9008 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9009 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9010 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9011 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9013 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9014 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9015 | } |
| 9016 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9017 | enforceTelephonyFeatureWithException(callingPackage, |
| 9018 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9020 | final long identity = Binder.clearCallingIdentity(); |
| 9021 | try { |
| 9022 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9023 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9024 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9025 | } |
| 9026 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9027 | } finally { |
| 9028 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9029 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9030 | } |
| 9031 | |
| 9032 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9033 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9034 | * |
| 9035 | * @throws SecurityException if the caller does not have the required permission |
| 9036 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9037 | @VisibleForTesting |
| 9038 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9039 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9040 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9041 | } |
| 9042 | |
| 9043 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9044 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9045 | * permission. |
| 9046 | * |
| 9047 | * @throws SecurityException if the caller does not have the required permission |
| 9048 | */ |
| 9049 | private void enforceSendSmsPermission() { |
| 9050 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9051 | } |
| 9052 | |
| 9053 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9054 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9055 | * users permission. |
| 9056 | * |
| 9057 | * @throws SecurityException if the caller does not have the required permission |
| 9058 | */ |
| 9059 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9060 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9061 | } |
| 9062 | |
| 9063 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9064 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9065 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9066 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9067 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9068 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9069 | final long identity = Binder.clearCallingIdentity(); |
| 9070 | try { |
| 9071 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9072 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9073 | if (componentName == null) { |
| 9074 | throw new SecurityException( |
| 9075 | "Caller not current active visual voicemail package[null]"); |
| 9076 | } |
| 9077 | String vvmPackage = componentName.getPackageName(); |
| 9078 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9079 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9080 | } |
| 9081 | } finally { |
| 9082 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9083 | } |
| 9084 | } |
| 9085 | |
| 9086 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9087 | * Return the application ID for the app type. |
| 9088 | * |
| 9089 | * @param subId the subscription ID that this request applies to. |
| 9090 | * @param appType the uicc app type. |
| 9091 | * @return Application ID for specificied app type, or null if no uicc. |
| 9092 | */ |
| 9093 | @Override |
| 9094 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9095 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9096 | |
| 9097 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9098 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9099 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9100 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9101 | |
| 9102 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9103 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9104 | if (phone == null) { |
| 9105 | return null; |
| 9106 | } |
| 9107 | String aid = null; |
| 9108 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9109 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9110 | .getApplicationByType(appType).getAid(); |
| 9111 | } catch (Exception e) { |
| 9112 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9113 | } |
| 9114 | return aid; |
| 9115 | } finally { |
| 9116 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9117 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9118 | } |
| 9119 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9120 | /** |
| 9121 | * Return the Electronic Serial Number. |
| 9122 | * |
| 9123 | * @param subId the subscription ID that this request applies to. |
| 9124 | * @return ESN or null if error. |
| 9125 | */ |
| 9126 | @Override |
| 9127 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9128 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9129 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9130 | |
| 9131 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9132 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9133 | if (phone == null) { |
| 9134 | return null; |
| 9135 | } |
| 9136 | String esn = null; |
| 9137 | try { |
| 9138 | esn = phone.getEsn(); |
| 9139 | } catch (Exception e) { |
| 9140 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9141 | } |
| 9142 | return esn; |
| 9143 | } finally { |
| 9144 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9145 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9146 | } |
| 9147 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9148 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9149 | * Return the Preferred Roaming List Version. |
| 9150 | * |
| 9151 | * @param subId the subscription ID that this request applies to. |
| 9152 | * @return PRLVersion or null if error. |
| 9153 | */ |
| 9154 | @Override |
| 9155 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9156 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9157 | |
| 9158 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9159 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9160 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9161 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9162 | |
| 9163 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9164 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9165 | if (phone == null) { |
| 9166 | return null; |
| 9167 | } |
| 9168 | String cdmaPrlVersion = null; |
| 9169 | try { |
| 9170 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9171 | } catch (Exception e) { |
| 9172 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9173 | } |
| 9174 | return cdmaPrlVersion; |
| 9175 | } finally { |
| 9176 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9177 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9178 | } |
| 9179 | |
| 9180 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9181 | * Get snapshot of Telephony histograms |
| 9182 | * @return List of Telephony histograms |
| 9183 | * @hide |
| 9184 | */ |
| 9185 | @Override |
| 9186 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9187 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9188 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9189 | |
| 9190 | final long identity = Binder.clearCallingIdentity(); |
| 9191 | try { |
| 9192 | return RIL.getTelephonyRILTimingHistograms(); |
| 9193 | } finally { |
| 9194 | Binder.restoreCallingIdentity(identity); |
| 9195 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9196 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9197 | |
| 9198 | /** |
| 9199 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9200 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9201 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9202 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9203 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9204 | * @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] | 9205 | */ |
| 9206 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9207 | @TelephonyManager.SetCarrierRestrictionResult |
| 9208 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9209 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9210 | |
| 9211 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9212 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9213 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9214 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9215 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9216 | if (carrierRestrictionRules == null) { |
| 9217 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9218 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9219 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9220 | final long identity = Binder.clearCallingIdentity(); |
| 9221 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9222 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9223 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9224 | } finally { |
| 9225 | Binder.restoreCallingIdentity(identity); |
| 9226 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9227 | } |
| 9228 | |
| 9229 | /** |
| 9230 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9231 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9232 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9233 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9234 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9235 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9236 | */ |
| 9237 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9238 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9239 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9240 | |
| 9241 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9242 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9243 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9244 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9245 | |
| 9246 | final long identity = Binder.clearCallingIdentity(); |
| 9247 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9248 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9249 | if (response instanceof CarrierRestrictionRules) { |
| 9250 | return (CarrierRestrictionRules) response; |
| 9251 | } |
| 9252 | // Response is an Exception of some kind, |
| 9253 | // which is signalled to the user as a NULL retval |
| 9254 | return null; |
| 9255 | } catch (Exception e) { |
| 9256 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9257 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9258 | } finally { |
| 9259 | Binder.restoreCallingIdentity(identity); |
| 9260 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9261 | } |
| 9262 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9263 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9264 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9265 | * through the callback. |
| 9266 | * |
| 9267 | * @param callback The callback that will be used to send the result. |
| 9268 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9269 | * the caller is not allowlisted. |
| 9270 | */ |
| 9271 | @Override |
| 9272 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9273 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9274 | |
| 9275 | enforceTelephonyFeatureWithException(packageName, |
| 9276 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9277 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9278 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9279 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9280 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9281 | throw new SecurityException("Not an authorized caller"); |
| 9282 | } |
| 9283 | final long identity = Binder.clearCallingIdentity(); |
| 9284 | try { |
| 9285 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9286 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9287 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9288 | } finally { |
| 9289 | Binder.restoreCallingIdentity(identity); |
| 9290 | } |
| 9291 | } |
| 9292 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9293 | @Override |
| 9294 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9295 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9296 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9297 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9298 | } |
| 9299 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9300 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9301 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9302 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9303 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9304 | } |
| 9305 | |
| 9306 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9307 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9308 | * @param subId the subscription ID that this action applies to. |
| 9309 | * @param enabled control enable or disable radio. |
| 9310 | * {@hide} |
| 9311 | */ |
| 9312 | @Override |
| 9313 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9314 | enforceModifyPermission(); |
| 9315 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9316 | |
| 9317 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9318 | if (phone == null) { |
| 9319 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9320 | return; |
| 9321 | } |
| 9322 | try { |
| 9323 | phone.carrierActionSetRadioEnabled(enabled); |
| 9324 | } catch (Exception e) { |
| 9325 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9326 | } finally { |
| 9327 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9328 | } |
| 9329 | } |
| 9330 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9331 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9332 | * Enable or disable Voice over NR (VoNR) |
| 9333 | * @param subId the subscription ID that this action applies to. |
| 9334 | * @param enabled enable or disable VoNR. |
| 9335 | * @return operation result. |
| 9336 | */ |
| 9337 | @Override |
| 9338 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9339 | enforceModifyPermission(); |
| 9340 | final Phone phone = getPhone(subId); |
| 9341 | |
| 9342 | final long identity = Binder.clearCallingIdentity(); |
| 9343 | if (phone == null) { |
| 9344 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9345 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9346 | } |
| 9347 | |
| 9348 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9349 | try { |
| 9350 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9351 | workSource); |
| 9352 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9353 | |
| 9354 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9355 | if (DBG) { |
| 9356 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9357 | } |
| 9358 | SubscriptionManager.setSubscriptionProperty( |
| 9359 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9360 | (enabled ? "1" : "0")); |
| 9361 | } |
| 9362 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9363 | return result; |
| 9364 | } finally { |
| 9365 | Binder.restoreCallingIdentity(identity); |
| 9366 | } |
| 9367 | } |
| 9368 | |
| 9369 | /** |
| 9370 | * Is voice over NR enabled |
| 9371 | * @return true if VoNR is enabled else false |
| 9372 | */ |
| 9373 | @Override |
| 9374 | public boolean isVoNrEnabled(int subId) { |
| 9375 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9376 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9377 | final long identity = Binder.clearCallingIdentity(); |
| 9378 | try { |
| 9379 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9380 | null, subId, workSource); |
| 9381 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9382 | return isEnabled; |
| 9383 | } finally { |
| 9384 | Binder.restoreCallingIdentity(identity); |
| 9385 | } |
| 9386 | } |
| 9387 | |
| 9388 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9389 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9390 | * network status based on which carrier apps could apply actions accordingly, |
| 9391 | * enable/disable default url handler for example. |
| 9392 | * |
| 9393 | * @param subId the subscription ID that this action applies to. |
| 9394 | * @param report control start/stop reporting the default network status. |
| 9395 | * {@hide} |
| 9396 | */ |
| 9397 | @Override |
| 9398 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9399 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9400 | |
| 9401 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9402 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9403 | "carrierActionReportDefaultNetworkStatus"); |
| 9404 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9405 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9406 | |
| 9407 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9408 | if (phone == null) { |
| 9409 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9410 | return; |
| 9411 | } |
| 9412 | try { |
| 9413 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9414 | } catch (Exception e) { |
| 9415 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9416 | } finally { |
| 9417 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9418 | } |
| 9419 | } |
| 9420 | |
| 9421 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9422 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9423 | * @param subId the subscription ID that this action applies to. |
| 9424 | * {@hide} |
| 9425 | */ |
| 9426 | @Override |
| 9427 | public void carrierActionResetAll(int subId) { |
| 9428 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9429 | |
| 9430 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9431 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9432 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9433 | final Phone phone = getPhone(subId); |
| 9434 | if (phone == null) { |
| 9435 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9436 | return; |
| 9437 | } |
| 9438 | try { |
| 9439 | phone.carrierActionResetAll(); |
| 9440 | } catch (Exception e) { |
| 9441 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9442 | } |
| 9443 | } |
| 9444 | |
| 9445 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9446 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9447 | * bug report is being generated. |
| 9448 | */ |
| 9449 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9450 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9451 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9452 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9453 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9454 | + Binder.getCallingPid() |
| 9455 | + ", uid=" + Binder.getCallingUid() |
| 9456 | + "without permission " |
| 9457 | + android.Manifest.permission.DUMP); |
| 9458 | return; |
| 9459 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9460 | try { |
| 9461 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9462 | } catch (Exception e) { |
| 9463 | writer.println("Failed to dump phone information: " + e); |
| 9464 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9465 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9466 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9467 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9468 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9469 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9470 | @NonNull String[] args) { |
| 9471 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9472 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9473 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9474 | } |
| 9475 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9476 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9477 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9478 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9479 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9480 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9481 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9482 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9483 | */ |
| 9484 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9485 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9486 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9487 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9488 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9489 | try { |
| 9490 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9491 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9492 | } catch (SecurityException se) { |
| 9493 | enforceModifyPermission(); |
| 9494 | } |
| 9495 | } else { |
| 9496 | enforceModifyPermission(); |
| 9497 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9498 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9499 | enforceTelephonyFeatureWithException(callingPackage, |
| 9500 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9501 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9502 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9503 | final long identity = Binder.clearCallingIdentity(); |
| 9504 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9505 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9506 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9507 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9508 | callingUid, callingPackage, null, null); |
| 9509 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9510 | Phone phone = getPhone(subId); |
| 9511 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9512 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9513 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9514 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9515 | phone.getDataSettingsManager().setDataEnabled( |
| 9516 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9517 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9518 | } |
| 9519 | } finally { |
| 9520 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9521 | } |
| 9522 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9523 | |
| 9524 | /** |
| 9525 | * Get Client request stats |
| 9526 | * @return List of Client Request Stats |
| 9527 | * @hide |
| 9528 | */ |
| 9529 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9530 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9531 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9532 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9533 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9534 | return null; |
| 9535 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9536 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9537 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9538 | final long identity = Binder.clearCallingIdentity(); |
| 9539 | try { |
| 9540 | if (phone != null) { |
| 9541 | return phone.getClientRequestStats(); |
| 9542 | } |
| 9543 | |
| 9544 | return null; |
| 9545 | } finally { |
| 9546 | Binder.restoreCallingIdentity(identity); |
| 9547 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9548 | } |
| 9549 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9550 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9551 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9552 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9553 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9554 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9555 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9556 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9557 | // commands that plumb through the RIL as root, like so: |
| 9558 | // $ adb root |
| 9559 | // $ adb shell cmd phone ... |
| 9560 | packageName = "root"; |
| 9561 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9562 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9563 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9564 | |
| 9565 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9566 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9567 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9568 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9569 | * @param state State of SIM (power down, power up, pass through) |
| 9570 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9571 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9572 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9573 | * |
| 9574 | **/ |
| 9575 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9576 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9577 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9578 | |
| 9579 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9580 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9581 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9582 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9583 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9584 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9585 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9586 | final long identity = Binder.clearCallingIdentity(); |
| 9587 | try { |
| 9588 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9589 | phone.setSimPowerState(state, null, workSource); |
| 9590 | } |
| 9591 | } finally { |
| 9592 | Binder.restoreCallingIdentity(identity); |
| 9593 | } |
| 9594 | } |
| 9595 | |
| 9596 | /** |
| 9597 | * Set SIM card power state. |
| 9598 | * |
| 9599 | * @param slotIndex SIM slot id. |
| 9600 | * @param state State of SIM (power down, power up, pass through) |
| 9601 | * @param callback callback to trigger after success or failure |
| 9602 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9603 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9604 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9605 | * |
| 9606 | **/ |
| 9607 | @Override |
| 9608 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9609 | IIntegerConsumer callback) { |
| 9610 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9611 | |
| 9612 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9613 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9614 | "setSimPowerStateForSlotWithCallback"); |
| 9615 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9616 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9617 | |
| 9618 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9619 | |
| 9620 | final long identity = Binder.clearCallingIdentity(); |
| 9621 | try { |
| 9622 | if (phone != null) { |
| 9623 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9624 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9625 | } |
| 9626 | } finally { |
| 9627 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9628 | } |
| 9629 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9630 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9631 | private boolean isUssdApiAllowed(int subId) { |
| 9632 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9633 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9634 | if (configManager == null) { |
| 9635 | return false; |
| 9636 | } |
| 9637 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9638 | if (pb == null) { |
| 9639 | return false; |
| 9640 | } |
| 9641 | return pb.getBoolean( |
| 9642 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9643 | } |
| 9644 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9645 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9646 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9647 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9648 | * @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] | 9649 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9650 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9651 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9652 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9653 | |
| 9654 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9655 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9656 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9657 | final long identity = Binder.clearCallingIdentity(); |
| 9658 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9659 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9660 | } finally { |
| 9661 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9662 | } |
| 9663 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9664 | |
| 9665 | /** |
| 9666 | * Get the current signal strength information for the given subscription. |
| 9667 | * Because this information is not updated when the device is in a low power state |
| 9668 | * it should not be relied-upon to be current. |
| 9669 | * @param subId Subscription index |
| 9670 | * @return the most recent cached signal strength info from the modem |
| 9671 | */ |
| 9672 | @Override |
| 9673 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9674 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9675 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9677 | final long identity = Binder.clearCallingIdentity(); |
| 9678 | try { |
| 9679 | Phone p = getPhone(subId); |
| 9680 | if (p == null) { |
| 9681 | return null; |
| 9682 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9683 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9684 | return p.getSignalStrength(); |
| 9685 | } finally { |
| 9686 | Binder.restoreCallingIdentity(identity); |
| 9687 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9688 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9689 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9690 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9691 | * Get the current modem radio state for the given slot. |
| 9692 | * @param slotIndex slot index. |
| 9693 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9694 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9695 | * @return the current radio power state from the modem |
| 9696 | */ |
| 9697 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9698 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9699 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9700 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9702 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9703 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9704 | } |
| 9705 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9706 | enforceTelephonyFeatureWithException(callingPackage, |
| 9707 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9708 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9709 | final long identity = Binder.clearCallingIdentity(); |
| 9710 | try { |
| 9711 | return phone.getRadioPowerState(); |
| 9712 | } finally { |
| 9713 | Binder.restoreCallingIdentity(identity); |
| 9714 | } |
| 9715 | } |
| 9716 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9717 | } |
| 9718 | |
| 9719 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9720 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9721 | * |
| 9722 | * <p>Requires one of the following permissions: |
| 9723 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9724 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9725 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9726 | * privileges. |
| 9727 | * |
| 9728 | * @param subId subscription id |
| 9729 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9730 | * {@code false}. |
| 9731 | */ |
| 9732 | @Override |
| 9733 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9734 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9735 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9736 | try { |
| 9737 | mApp.enforceCallingOrSelfPermission( |
| 9738 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9739 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9740 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9741 | mApp.enforceCallingOrSelfPermission( |
| 9742 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9743 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9744 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9745 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9746 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9747 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9748 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9749 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9750 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9751 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9752 | boolean isEnabled = false; |
| 9753 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9754 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9755 | Phone phone = getPhone(subId); |
| 9756 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9757 | } finally { |
| 9758 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9759 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9760 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9761 | } |
| 9762 | |
| 9763 | |
| 9764 | /** |
| 9765 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9766 | * |
| 9767 | * <p> Requires permission: |
| 9768 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9769 | * privileges. |
| 9770 | * |
| 9771 | * @param subId subscription id |
| 9772 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9773 | */ |
| 9774 | @Override |
| 9775 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9777 | mApp, subId, "setDataRoamingEnabled"); |
| 9778 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9779 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9780 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9781 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9782 | final long identity = Binder.clearCallingIdentity(); |
| 9783 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9784 | Phone phone = getPhone(subId); |
| 9785 | if (phone != null) { |
| 9786 | phone.setDataRoamingEnabled(isEnabled); |
| 9787 | } |
| 9788 | } finally { |
| 9789 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9790 | } |
| 9791 | } |
| 9792 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9793 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9794 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9795 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9796 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9797 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9798 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9799 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9800 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9801 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9802 | boolean isAllowed = true; |
| 9803 | final long identity = Binder.clearCallingIdentity(); |
| 9804 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9805 | Phone phone = getPhone(subId); |
| 9806 | if (phone != null) { |
| 9807 | isAllowed = phone.isCspPlmnEnabled(); |
| 9808 | } |
| 9809 | } finally { |
| 9810 | Binder.restoreCallingIdentity(identity); |
| 9811 | } |
| 9812 | return isAllowed; |
| 9813 | } |
| 9814 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9815 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9816 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9817 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9818 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9819 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9820 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9821 | if (phone == null) { |
| 9822 | return false; |
| 9823 | } |
| 9824 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9825 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9826 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9827 | } |
| 9828 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9829 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9830 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9831 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9832 | mApp.getSystemService(AppOpsManager.class) |
| 9833 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9834 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9835 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9836 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9837 | try { |
| 9838 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9839 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9840 | } catch (SecurityException e) { |
| 9841 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9842 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9843 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9844 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9845 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9846 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9847 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9848 | |
| 9849 | enforceTelephonyFeatureWithException(callingPackage, |
| 9850 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9851 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9852 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9853 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9854 | Binder.getCallingUid())) { |
| 9855 | isIccIdAccessRestricted = true; |
| 9856 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9857 | final long identity = Binder.clearCallingIdentity(); |
| 9858 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9859 | UiccController uiccController = UiccController.getInstance(); |
| 9860 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9861 | if (hasReadPermission) { |
| 9862 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9863 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9864 | |
| 9865 | // Remove private info if the caller doesn't have access |
| 9866 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9867 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9868 | //setting the value after compatibility check |
| 9869 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9870 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9871 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9872 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9873 | if (card == null) { |
| 9874 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9875 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9876 | continue; |
| 9877 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9878 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9879 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9880 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9881 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9882 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9883 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9884 | for (UiccPortInfo portInfo : portInfos) { |
| 9885 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9886 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9887 | if (port == null) { |
| 9888 | // assume no access if port is null |
| 9889 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9890 | continue; |
| 9891 | } |
| 9892 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9893 | uiccPortInfos.add(portInfo); |
| 9894 | } else { |
| 9895 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9896 | } |
| 9897 | } |
| 9898 | filteredInfos.add(new UiccCardInfo( |
| 9899 | cardInfo.isEuicc(), |
| 9900 | cardInfo.getCardId(), |
| 9901 | null, |
| 9902 | cardInfo.getPhysicalSlotIndex(), |
| 9903 | cardInfo.isRemovable(), |
| 9904 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9905 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9906 | } |
| 9907 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9908 | } finally { |
| 9909 | Binder.restoreCallingIdentity(identity); |
| 9910 | } |
| 9911 | } |
| 9912 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9913 | /** |
| 9914 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9915 | * generally private and require carrier privileges to view. |
| 9916 | * |
| 9917 | * @hide |
| 9918 | */ |
| 9919 | @NonNull |
| 9920 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9921 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9922 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9923 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9924 | } |
| 9925 | return new UiccCardInfo( |
| 9926 | cardInfo.isEuicc(), |
| 9927 | cardInfo.getCardId(), |
| 9928 | null, |
| 9929 | cardInfo.getPhysicalSlotIndex(), |
| 9930 | cardInfo.isRemovable(), |
| 9931 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9932 | portinfo |
| 9933 | ); |
| 9934 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9935 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9936 | /** |
| 9937 | * @hide |
| 9938 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9939 | * These values are generally private and require carrier privileges to view. |
| 9940 | */ |
| 9941 | @NonNull |
| 9942 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9943 | return new UiccPortInfo( |
| 9944 | UiccPortInfo.ICCID_REDACTED, |
| 9945 | portInfo.getPortIndex(), |
| 9946 | portInfo.getLogicalSlotIndex(), |
| 9947 | portInfo.isActive() |
| 9948 | ); |
| 9949 | } |
| 9950 | @Override |
| 9951 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9952 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9953 | mApp.getSystemService(AppOpsManager.class) |
| 9954 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9955 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9956 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9957 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9958 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9959 | // we are reading iccId which is PII data. |
| 9960 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9961 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9962 | enforceTelephonyFeatureWithException(callingPackage, |
| 9963 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9964 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9965 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9966 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9967 | Binder.getCallingUid())) { |
| 9968 | isLogicalSlotAccessRestricted = true; |
| 9969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9970 | final long identity = Binder.clearCallingIdentity(); |
| 9971 | try { |
| 9972 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9973 | if (slots == null || slots.length == 0) { |
| 9974 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9975 | return null; |
| 9976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9977 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9978 | for (int i = 0; i < slots.length; i++) { |
| 9979 | UiccSlot slot = slots[i]; |
| 9980 | if (slot == null) { |
| 9981 | continue; |
| 9982 | } |
| 9983 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9984 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9985 | UiccCard card = slot.getUiccCard(); |
| 9986 | if (card != null) { |
| 9987 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9988 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9989 | cardId = slot.getEid(); |
| 9990 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9991 | // If cardId is null, use iccId of default port as cardId. |
| 9992 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9993 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9994 | } |
| 9995 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9996 | if (cardId != null) { |
| 9997 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9998 | // if cardId is an EID, it's all digits so this is fine |
| 9999 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10000 | } |
| 10001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10002 | int cardState = 0; |
| 10003 | switch (slot.getCardState()) { |
| 10004 | case CARDSTATE_ABSENT: |
| 10005 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10006 | break; |
| 10007 | case CARDSTATE_PRESENT: |
| 10008 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10009 | break; |
| 10010 | case CARDSTATE_ERROR: |
| 10011 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10012 | break; |
| 10013 | case CARDSTATE_RESTRICTED: |
| 10014 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10015 | break; |
| 10016 | default: |
| 10017 | break; |
| 10018 | |
| 10019 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10020 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10021 | int[] portIndexes = slot.getPortList(); |
| 10022 | for (int portIdx : portIndexes) { |
| 10023 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10024 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10025 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10026 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10027 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10028 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10029 | slot.isEuicc(), |
| 10030 | cardId, |
| 10031 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10032 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10033 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10034 | //setting the value after compatibility check |
| 10035 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10036 | } |
| 10037 | return infos; |
| 10038 | } finally { |
| 10039 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10040 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10041 | } |
| 10042 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10043 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10044 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10045 | boolean hasReadPermission) { |
| 10046 | String iccId = slot.getIccId(portIndex); |
| 10047 | if (hasReadPermission) { // if has read permission |
| 10048 | return iccId; |
| 10049 | } else { |
| 10050 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10051 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10052 | // if no read permission, checking carrier privilege access |
| 10053 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10054 | return iccId; |
| 10055 | } |
| 10056 | } |
| 10057 | } |
| 10058 | // No read permission or carrier privilege access. |
| 10059 | return UiccPortInfo.ICCID_REDACTED; |
| 10060 | } |
| 10061 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10062 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10063 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10064 | public boolean switchSlots(int[] physicalSlots) { |
| 10065 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10066 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10067 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10068 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10070 | final long identity = Binder.clearCallingIdentity(); |
| 10071 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10072 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10073 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10074 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10075 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10076 | physicalSlots[i], i)); |
| 10077 | } |
| 10078 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10079 | } finally { |
| 10080 | Binder.restoreCallingIdentity(identity); |
| 10081 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10082 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10083 | |
| 10084 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10085 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10086 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10087 | enforceModifyPermission(); |
| 10088 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10089 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10090 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10091 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10092 | final long identity = Binder.clearCallingIdentity(); |
| 10093 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10094 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10095 | } finally { |
| 10096 | Binder.restoreCallingIdentity(identity); |
| 10097 | } |
| 10098 | } |
| 10099 | |
| 10100 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10101 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10102 | enforceTelephonyFeatureWithException(callingPackage, |
| 10103 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10104 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10105 | final long identity = Binder.clearCallingIdentity(); |
| 10106 | try { |
| 10107 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10108 | } finally { |
| 10109 | Binder.restoreCallingIdentity(identity); |
| 10110 | } |
| 10111 | } |
| 10112 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10113 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10114 | * A test API to reload the UICC profile. |
| 10115 | * |
| 10116 | * <p>Requires that the calling app has permission |
| 10117 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10118 | * @hide |
| 10119 | */ |
| 10120 | @Override |
| 10121 | public void refreshUiccProfile(int subId) { |
| 10122 | enforceModifyPermission(); |
| 10123 | |
| 10124 | final long identity = Binder.clearCallingIdentity(); |
| 10125 | try { |
| 10126 | Phone phone = getPhone(subId); |
| 10127 | if (phone == null) { |
| 10128 | return; |
| 10129 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10130 | UiccPort uiccPort = phone.getUiccPort(); |
| 10131 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10132 | return; |
| 10133 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10134 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10135 | if (uiccProfile == null) { |
| 10136 | return; |
| 10137 | } |
| 10138 | uiccProfile.refresh(); |
| 10139 | } finally { |
| 10140 | Binder.restoreCallingIdentity(identity); |
| 10141 | } |
| 10142 | } |
| 10143 | |
| 10144 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10145 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10146 | */ |
| 10147 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10148 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10149 | } |
| 10150 | |
| 10151 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10152 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10153 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10154 | */ |
| 10155 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10156 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10157 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10158 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10159 | return list.get(phoneId); |
| 10160 | } |
| 10161 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10162 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10163 | |
| 10164 | @Override |
| 10165 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10166 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10167 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10168 | |
| 10169 | final long identity = Binder.clearCallingIdentity(); |
| 10170 | try { |
| 10171 | final Phone phone = getPhone(subId); |
| 10172 | if (phone == null) { |
| 10173 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10174 | return; |
| 10175 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10176 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10177 | if (cpt != null) { |
| 10178 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10179 | } |
| 10180 | // 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] | 10181 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10182 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10183 | if (carrierPrivilegeRules == null) { |
| 10184 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10185 | } else { |
| 10186 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10187 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10188 | } finally { |
| 10189 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10190 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10191 | } |
| 10192 | |
| 10193 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10194 | public void setCarrierServicePackageOverride( |
| 10195 | int subId, String carrierServicePackage, String callingPackage) { |
| 10196 | TelephonyPermissions.enforceShellOnly( |
| 10197 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10198 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10199 | final long identity = Binder.clearCallingIdentity(); |
| 10200 | try { |
| 10201 | final Phone phone = getPhone(subId); |
| 10202 | if (phone == null || phone.getSubId() != subId) { |
| 10203 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10204 | throw new IllegalArgumentException("No phone for subid"); |
| 10205 | } |
| 10206 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10207 | if (cpt == null) { |
| 10208 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10209 | throw new IllegalStateException("No CPT for phone"); |
| 10210 | } |
| 10211 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10212 | } finally { |
| 10213 | Binder.restoreCallingIdentity(identity); |
| 10214 | } |
| 10215 | } |
| 10216 | |
| 10217 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10218 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10219 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10220 | |
| 10221 | final long identity = Binder.clearCallingIdentity(); |
| 10222 | try { |
| 10223 | final Phone phone = getPhone(subId); |
| 10224 | if (phone == null) { |
| 10225 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10226 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10227 | } |
| 10228 | return phone.getCarrierIdListVersion(); |
| 10229 | } finally { |
| 10230 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10231 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10232 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10233 | |
| 10234 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10235 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10236 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10237 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10238 | mApp, subId, callingPackage, callingFeatureId, |
| 10239 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10240 | return -1; |
| 10241 | } |
| 10242 | |
| 10243 | final long identity = Binder.clearCallingIdentity(); |
| 10244 | try { |
| 10245 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10246 | } finally { |
| 10247 | Binder.restoreCallingIdentity(identity); |
| 10248 | } |
| 10249 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10250 | |
| 10251 | @Override |
| 10252 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10253 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10254 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10255 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10256 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10257 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10258 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10259 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10260 | final long identity = Binder.clearCallingIdentity(); |
| 10261 | try { |
| 10262 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10263 | } finally { |
| 10264 | Binder.restoreCallingIdentity(identity); |
| 10265 | } |
| 10266 | } |
| 10267 | |
| 10268 | @Override |
| 10269 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10271 | mApp, subId, "setCdmaRoamingMode"); |
| 10272 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10273 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10274 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10275 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10276 | final long identity = Binder.clearCallingIdentity(); |
| 10277 | try { |
| 10278 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10279 | } finally { |
| 10280 | Binder.restoreCallingIdentity(identity); |
| 10281 | } |
| 10282 | } |
| 10283 | |
| 10284 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10285 | public int getCdmaSubscriptionMode(int subId) { |
| 10286 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10287 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10288 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10289 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10290 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10291 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10292 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10293 | final long identity = Binder.clearCallingIdentity(); |
| 10294 | try { |
| 10295 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10296 | } finally { |
| 10297 | Binder.restoreCallingIdentity(identity); |
| 10298 | } |
| 10299 | } |
| 10300 | |
| 10301 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10302 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10304 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10305 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10306 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10307 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10308 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10309 | final long identity = Binder.clearCallingIdentity(); |
| 10310 | try { |
| 10311 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10312 | } finally { |
| 10313 | Binder.restoreCallingIdentity(identity); |
| 10314 | } |
| 10315 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10316 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10317 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10318 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10319 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10320 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10321 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10322 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10323 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10324 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10325 | |
| 10326 | enforceTelephonyFeatureWithException(callingPackage, |
| 10327 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10328 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10329 | final long identity = Binder.clearCallingIdentity(); |
| 10330 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10331 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10332 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10333 | if (phone.getEmergencyNumberTracker() != null |
| 10334 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10335 | emergencyNumberListInternal.put( |
| 10336 | phone.getSubId(), |
| 10337 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10338 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10339 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10340 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10341 | } finally { |
| 10342 | Binder.restoreCallingIdentity(identity); |
| 10343 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10344 | } |
| 10345 | |
| 10346 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10347 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10348 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10349 | if (!exactMatch) { |
| 10350 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10351 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10352 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10353 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10354 | |
| 10355 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10356 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10357 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10358 | final long identity = Binder.clearCallingIdentity(); |
| 10359 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10360 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10361 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10362 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10363 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10364 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10365 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10366 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10367 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10368 | } |
| 10369 | return false; |
| 10370 | } finally { |
| 10371 | Binder.restoreCallingIdentity(identity); |
| 10372 | } |
| 10373 | } |
| 10374 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10375 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10376 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10377 | */ |
| 10378 | @Override |
| 10379 | public void startEmergencyCallbackMode() { |
| 10380 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10381 | "startEmergencyCallbackMode"); |
| 10382 | enforceModifyPermission(); |
| 10383 | final long identity = Binder.clearCallingIdentity(); |
| 10384 | try { |
| 10385 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10386 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10387 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10388 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10389 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10390 | gsmCdmaPhone.obtainMessage( |
| 10391 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10392 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10393 | } |
| 10394 | } |
| 10395 | } finally { |
| 10396 | Binder.restoreCallingIdentity(identity); |
| 10397 | } |
| 10398 | } |
| 10399 | |
| 10400 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10401 | * Update emergency number list for test mode. |
| 10402 | */ |
| 10403 | @Override |
| 10404 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10405 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10406 | "updateEmergencyNumberListTestMode"); |
| 10407 | |
| 10408 | final long identity = Binder.clearCallingIdentity(); |
| 10409 | try { |
| 10410 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10411 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10412 | if (tracker != null) { |
| 10413 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10414 | } |
| 10415 | } |
| 10416 | } finally { |
| 10417 | Binder.restoreCallingIdentity(identity); |
| 10418 | } |
| 10419 | } |
| 10420 | |
| 10421 | /** |
| 10422 | * Get the full emergency number list for test mode. |
| 10423 | */ |
| 10424 | @Override |
| 10425 | public List<String> getEmergencyNumberListTestMode() { |
| 10426 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10427 | "getEmergencyNumberListTestMode"); |
| 10428 | |
| 10429 | final long identity = Binder.clearCallingIdentity(); |
| 10430 | try { |
| 10431 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10432 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10433 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10434 | if (tracker != null) { |
| 10435 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10436 | emergencyNumbers.add(num.getNumber()); |
| 10437 | } |
| 10438 | } |
| 10439 | } |
| 10440 | return new ArrayList<>(emergencyNumbers); |
| 10441 | } finally { |
| 10442 | Binder.restoreCallingIdentity(identity); |
| 10443 | } |
| 10444 | } |
| 10445 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10446 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10447 | public int getEmergencyNumberDbVersion(int subId) { |
| 10448 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10449 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10450 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10451 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10452 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10453 | final long identity = Binder.clearCallingIdentity(); |
| 10454 | try { |
| 10455 | final Phone phone = getPhone(subId); |
| 10456 | if (phone == null) { |
| 10457 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10458 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10459 | } |
| 10460 | return phone.getEmergencyNumberDbVersion(); |
| 10461 | } finally { |
| 10462 | Binder.restoreCallingIdentity(identity); |
| 10463 | } |
| 10464 | } |
| 10465 | |
| 10466 | @Override |
| 10467 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10468 | enforceModifyPermission(); |
| 10469 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10470 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10471 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10472 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10473 | final long identity = Binder.clearCallingIdentity(); |
| 10474 | try { |
| 10475 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10476 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10477 | if (tracker != null) { |
| 10478 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10479 | } |
| 10480 | } |
| 10481 | } finally { |
| 10482 | Binder.restoreCallingIdentity(identity); |
| 10483 | } |
| 10484 | } |
| 10485 | |
| 10486 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10487 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10488 | enforceActiveEmergencySessionPermission(); |
| 10489 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10490 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10491 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10492 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10493 | final long identity = Binder.clearCallingIdentity(); |
| 10494 | try { |
| 10495 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10496 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10497 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10498 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10499 | } |
| 10500 | } |
| 10501 | } finally { |
| 10502 | Binder.restoreCallingIdentity(identity); |
| 10503 | } |
| 10504 | } |
| 10505 | |
| 10506 | @Override |
| 10507 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10508 | enforceActiveEmergencySessionPermission(); |
| 10509 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10510 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10511 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10512 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10513 | final long identity = Binder.clearCallingIdentity(); |
| 10514 | try { |
| 10515 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10516 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10517 | if (tracker != null) { |
| 10518 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10519 | } |
| 10520 | } |
| 10521 | } finally { |
| 10522 | Binder.restoreCallingIdentity(identity); |
| 10523 | } |
| 10524 | } |
| 10525 | |
| 10526 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10527 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10528 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10529 | Phone phone = getPhone(subId); |
| 10530 | if (phone == null) { |
| 10531 | return null; |
| 10532 | } |
| 10533 | final long identity = Binder.clearCallingIdentity(); |
| 10534 | try { |
| 10535 | UiccProfile profile = UiccController.getInstance() |
| 10536 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10537 | if (profile != null) { |
| 10538 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10539 | } |
| 10540 | } finally { |
| 10541 | Binder.restoreCallingIdentity(identity); |
| 10542 | } |
| 10543 | return null; |
| 10544 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10545 | |
| 10546 | /** |
| 10547 | * Enable or disable a modem stack. |
| 10548 | */ |
| 10549 | @Override |
| 10550 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10551 | enforceModifyPermission(); |
| 10552 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10553 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10554 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10555 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10556 | final long identity = Binder.clearCallingIdentity(); |
| 10557 | try { |
| 10558 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10559 | if (phone == null) { |
| 10560 | return false; |
| 10561 | } else { |
| 10562 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10563 | } |
| 10564 | } finally { |
| 10565 | Binder.restoreCallingIdentity(identity); |
| 10566 | } |
| 10567 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10568 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10569 | /** |
| 10570 | * Whether a modem stack is enabled or not. |
| 10571 | */ |
| 10572 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10573 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10574 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10575 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10576 | if (phone == null) return false; |
| 10577 | |
| 10578 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10579 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10580 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10581 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10582 | } |
| 10583 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10584 | enforceTelephonyFeatureWithException(callingPackage, |
| 10585 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10586 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10587 | final long identity = Binder.clearCallingIdentity(); |
| 10588 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10589 | try { |
| 10590 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10591 | } catch (NoSuchElementException ex) { |
| 10592 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10593 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10594 | } finally { |
| 10595 | Binder.restoreCallingIdentity(identity); |
| 10596 | } |
| 10597 | } |
| 10598 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10599 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10600 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10601 | enforceModifyPermission(); |
| 10602 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10603 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10604 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10605 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10606 | final long identity = Binder.clearCallingIdentity(); |
| 10607 | try { |
| 10608 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10609 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10610 | .commit(); |
| 10611 | } finally { |
| 10612 | Binder.restoreCallingIdentity(identity); |
| 10613 | } |
| 10614 | } |
| 10615 | |
| 10616 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10617 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10618 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10619 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10620 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10621 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10622 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10623 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10624 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10625 | enforceTelephonyFeatureWithException(callingPackage, |
| 10626 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10627 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10628 | final long identity = Binder.clearCallingIdentity(); |
| 10629 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10630 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10631 | } finally { |
| 10632 | Binder.restoreCallingIdentity(identity); |
| 10633 | } |
| 10634 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10635 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10636 | @TelephonyManager.IsMultiSimSupportedResult |
| 10637 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10638 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10639 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10640 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10641 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10642 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10643 | } |
| 10644 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10645 | // supported by the modem, indicate that it is restricted. |
| 10646 | PhoneCapability staticCapability = |
| 10647 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10648 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10649 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10650 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10651 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10652 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10653 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10654 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10655 | } |
| 10656 | // Check if support of multiple SIMs is restricted by carrier |
| 10657 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10658 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10659 | } |
| 10660 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10661 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10662 | } |
| 10663 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10664 | /** |
| 10665 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10666 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10667 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10668 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10669 | * @param numOfSims number of active sims we want to switch to |
| 10670 | */ |
| 10671 | @Override |
| 10672 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10673 | if (numOfSims == 1) { |
| 10674 | enforceModifyPermission(); |
| 10675 | } else { |
| 10676 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10677 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10678 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10679 | |
| 10680 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10681 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10682 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10683 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10684 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10685 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10686 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10687 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10688 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10689 | return; |
| 10690 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10691 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10692 | } finally { |
| 10693 | Binder.restoreCallingIdentity(identity); |
| 10694 | } |
| 10695 | } |
| 10696 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10697 | @Override |
| 10698 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10699 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10700 | |
| 10701 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10702 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10703 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10704 | Phone phone = getPhone(subId); |
| 10705 | if (phone == null) { |
| 10706 | return false; |
| 10707 | } |
| 10708 | final long identity = Binder.clearCallingIdentity(); |
| 10709 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10710 | UiccPort uiccPort = phone.getUiccPort(); |
| 10711 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10712 | return false; |
| 10713 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10714 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10715 | if (uiccProfile == null) { |
| 10716 | return false; |
| 10717 | } |
| 10718 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10719 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10720 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10721 | } |
| 10722 | return false; |
| 10723 | } finally { |
| 10724 | Binder.restoreCallingIdentity(identity); |
| 10725 | } |
| 10726 | } |
| 10727 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10728 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10729 | * Get whether making changes to modem configurations will trigger reboot. |
| 10730 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10731 | */ |
| 10732 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10733 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10734 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10735 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10736 | mApp, subId, callingPackage, callingFeatureId, |
| 10737 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10738 | return false; |
| 10739 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10740 | |
| 10741 | enforceTelephonyFeatureWithException(callingPackage, |
| 10742 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10743 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10744 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10745 | final long identity = Binder.clearCallingIdentity(); |
| 10746 | try { |
| 10747 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10748 | } finally { |
| 10749 | Binder.restoreCallingIdentity(identity); |
| 10750 | } |
| 10751 | } |
| 10752 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10753 | private void updateModemStateMetrics() { |
| 10754 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10755 | // TODO: check the state for each modem if the api is ready. |
| 10756 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10757 | } |
| 10758 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10759 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10760 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10761 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10762 | // Verify that the callingPackage belongs to the calling UID |
| 10763 | mApp.getSystemService(AppOpsManager.class) |
| 10764 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10765 | |
| 10766 | enforceTelephonyFeatureWithException(callingPackage, |
| 10767 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10768 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10769 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10770 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10771 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10772 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10773 | if (slotInfos != null) { |
| 10774 | for (int i = 0; i < slotInfos.length; i++) { |
| 10775 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10776 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10777 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10778 | portInfo.getLogicalSlotIndex())); |
| 10779 | } |
| 10780 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10781 | } |
| 10782 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10783 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10784 | } finally { |
| 10785 | Binder.restoreCallingIdentity(identity); |
| 10786 | } |
| 10787 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10788 | |
| 10789 | /** |
| 10790 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10791 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10792 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10793 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10794 | @Override |
| 10795 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10796 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10797 | } |
| 10798 | |
| 10799 | /** |
| 10800 | * Get the HAL Version of a specific service |
| 10801 | */ |
| 10802 | @Override |
| 10803 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10804 | Phone phone = getDefaultPhone(); |
| 10805 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10806 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10807 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10808 | return hv.major * 100 + hv.minor; |
| 10809 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10810 | |
| 10811 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10812 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10813 | * |
| 10814 | * @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] | 10815 | */ |
| 10816 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10817 | public @Nullable String getCurrentPackageName() { |
| 10818 | PackageManager pm = mApp.getPackageManager(); |
| 10819 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10820 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10821 | } |
| 10822 | |
| 10823 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10824 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10825 | * corresponding network requests on a subId. |
| 10826 | * |
| 10827 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10828 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10829 | * 2) APN is un-metered for this subscription, or |
| 10830 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10831 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10832 | * |
| 10833 | * @return whether data is allowed for a apn type. |
| 10834 | * |
| 10835 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10836 | */ |
| 10837 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10838 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10839 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10840 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10841 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10842 | enforceTelephonyFeatureWithException(callingPackage, |
| 10843 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10844 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10845 | // Now that all security checks passes, perform the operation as ourselves. |
| 10846 | final long identity = Binder.clearCallingIdentity(); |
| 10847 | try { |
| 10848 | Phone phone = getPhone(subId); |
| 10849 | if (phone == null) return false; |
| 10850 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10851 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10852 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10853 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10854 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10855 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10856 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10857 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10858 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10859 | } finally { |
| 10860 | Binder.restoreCallingIdentity(identity); |
| 10861 | } |
| 10862 | } |
| 10863 | |
| 10864 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10865 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10866 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10867 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10868 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10869 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10870 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10871 | // Now that all security checks passes, perform the operation as ourselves. |
| 10872 | final long identity = Binder.clearCallingIdentity(); |
| 10873 | try { |
| 10874 | Phone phone = getPhone(subId); |
| 10875 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10876 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10877 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10878 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10879 | } finally { |
| 10880 | Binder.restoreCallingIdentity(identity); |
| 10881 | } |
| 10882 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10883 | |
| 10884 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10885 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10886 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10887 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10888 | |
| 10889 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10890 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10891 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10892 | long token = Binder.clearCallingIdentity(); |
| 10893 | try { |
| 10894 | Phone phone = getPhone(subscriptionId); |
| 10895 | if (phone == null) { |
| 10896 | try { |
| 10897 | if (resultCallback != null) { |
| 10898 | resultCallback.accept(false); |
| 10899 | } |
| 10900 | } catch (RemoteException e) { |
| 10901 | // ignore |
| 10902 | } |
| 10903 | return; |
| 10904 | } |
| 10905 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10906 | Pair.create(specifiers, (x) -> { |
| 10907 | try { |
| 10908 | if (resultCallback != null) { |
| 10909 | resultCallback.accept(x); |
| 10910 | } |
| 10911 | } catch (RemoteException e) { |
| 10912 | // ignore |
| 10913 | } |
| 10914 | }); |
| 10915 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10916 | } finally { |
| 10917 | Binder.restoreCallingIdentity(token); |
| 10918 | } |
| 10919 | } |
| 10920 | |
| 10921 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10922 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10923 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10924 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10925 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10926 | |
| 10927 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10928 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10929 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10930 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10931 | final long identity = Binder.clearCallingIdentity(); |
| 10932 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10933 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10934 | if (result instanceof IllegalStateException) { |
| 10935 | throw (IllegalStateException) result; |
| 10936 | } |
| 10937 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10938 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10939 | return specifiers; |
| 10940 | } finally { |
| 10941 | Binder.restoreCallingIdentity(identity); |
| 10942 | } |
| 10943 | } |
| 10944 | |
| 10945 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10946 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10947 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10948 | |
| 10949 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10950 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10951 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10952 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10953 | } |
| 10954 | |
| 10955 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10956 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10957 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10958 | if (callingPackage == null) { |
| 10959 | callingPackage = getCurrentPackageName(); |
| 10960 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10961 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10962 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10963 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10964 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10965 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10966 | } |
| 10967 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10968 | Intent intent = new Intent(); |
| 10969 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10970 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10971 | // Bring up choose default SMS subscription dialog right now |
| 10972 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10973 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10974 | mApp.startActivity(intent); |
| 10975 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10976 | |
| 10977 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10978 | public void showSwitchToManagedProfileDialog() { |
| 10979 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10980 | try { |
| 10981 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10982 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10983 | // for work telephony. |
| 10984 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10985 | intent.setData(Uri.parse("smsto:")); |
| 10986 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10987 | mApp.startActivity(intent); |
| 10988 | } catch (ActivityNotFoundException e) { |
| 10989 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10990 | Intent intent = new Intent(); |
| 10991 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10992 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10993 | mApp.startActivity(intent); |
| 10994 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10995 | } |
| 10996 | |
| 10997 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10998 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10999 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11000 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11001 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11002 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11003 | final long identity = Binder.clearCallingIdentity(); |
| 11004 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11005 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11006 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11007 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11008 | return carrierUAProfUrl; |
| 11009 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11010 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11011 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11012 | } finally { |
| 11013 | Binder.restoreCallingIdentity(identity); |
| 11014 | } |
| 11015 | } |
| 11016 | |
| 11017 | @Override |
| 11018 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11019 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11020 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11021 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11022 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11023 | final long identity = Binder.clearCallingIdentity(); |
| 11024 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11025 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11026 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11027 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11028 | return carrierUserAgent; |
| 11029 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11030 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11031 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11032 | } finally { |
| 11033 | Binder.restoreCallingIdentity(identity); |
| 11034 | } |
| 11035 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11036 | |
| 11037 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11038 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11039 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11040 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11041 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11042 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11043 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11044 | final long identity = Binder.clearCallingIdentity(); |
| 11045 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11046 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11047 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11048 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11049 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11050 | } finally { |
| 11051 | Binder.restoreCallingIdentity(identity); |
| 11052 | } |
| 11053 | } |
| 11054 | |
| 11055 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11056 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11057 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11058 | enforceModifyPermission(); |
| 11059 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11060 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11061 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11062 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11063 | final long identity = Binder.clearCallingIdentity(); |
| 11064 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11065 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11066 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11067 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11068 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11069 | } finally { |
| 11070 | Binder.restoreCallingIdentity(identity); |
| 11071 | } |
| 11072 | } |
| 11073 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11074 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11075 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11076 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11077 | * otherwise. |
| 11078 | */ |
| 11079 | @Override |
| 11080 | public void setCepEnabled(boolean isCepEnabled) { |
| 11081 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11082 | |
| 11083 | final long identity = Binder.clearCallingIdentity(); |
| 11084 | try { |
| 11085 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11086 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11087 | Phone defaultPhone = phone.getImsPhone(); |
| 11088 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11089 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11090 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11091 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11092 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11093 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11094 | + imsPhone.getMsisdn()); |
| 11095 | } |
| 11096 | } |
| 11097 | } finally { |
| 11098 | Binder.restoreCallingIdentity(identity); |
| 11099 | } |
| 11100 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11101 | |
| 11102 | /** |
| 11103 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11104 | * |
| 11105 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11106 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11107 | * before being read. |
| 11108 | */ |
| 11109 | @Override |
| 11110 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11111 | isCompressed) { |
| 11112 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11113 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11114 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11115 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11116 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11117 | |
| 11118 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11119 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11120 | Binder.getCallingUserHandle())) { |
| 11121 | if (!isImsAvailableOnDevice()) { |
| 11122 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11123 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11124 | throw new IllegalStateException("IMS not available on device."); |
| 11125 | } |
| 11126 | } else { |
| 11127 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11128 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11129 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11130 | } |
| 11131 | |
| 11132 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11133 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11134 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11135 | } finally { |
| 11136 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11137 | } |
| 11138 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11139 | |
| 11140 | @Override |
| 11141 | public boolean isIccLockEnabled(int subId) { |
| 11142 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11143 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11144 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11145 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11146 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11147 | // Now that all security checks passes, perform the operation as ourselves. |
| 11148 | final long identity = Binder.clearCallingIdentity(); |
| 11149 | try { |
| 11150 | Phone phone = getPhone(subId); |
| 11151 | if (phone != null && phone.getIccCard() != null) { |
| 11152 | return phone.getIccCard().getIccLockEnabled(); |
| 11153 | } else { |
| 11154 | return false; |
| 11155 | } |
| 11156 | } finally { |
| 11157 | Binder.restoreCallingIdentity(identity); |
| 11158 | } |
| 11159 | } |
| 11160 | |
| 11161 | /** |
| 11162 | * Set the ICC pin lock enabled or disabled. |
| 11163 | * |
| 11164 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11165 | * three cases: |
| 11166 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11167 | * successfully. |
| 11168 | * - Positive number and zero for remaining password attempts. |
| 11169 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11170 | * |
| 11171 | */ |
| 11172 | @Override |
| 11173 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11174 | enforceModifyPermission(); |
| 11175 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11176 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11177 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11178 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11179 | Phone phone = getPhone(subId); |
| 11180 | if (phone == null) { |
| 11181 | return 0; |
| 11182 | } |
| 11183 | // Now that all security checks passes, perform the operation as ourselves. |
| 11184 | final long identity = Binder.clearCallingIdentity(); |
| 11185 | try { |
| 11186 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11187 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11188 | return attemptsRemaining; |
| 11189 | |
| 11190 | } catch (Exception e) { |
| 11191 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11192 | } finally { |
| 11193 | Binder.restoreCallingIdentity(identity); |
| 11194 | } |
| 11195 | return 0; |
| 11196 | } |
| 11197 | |
| 11198 | /** |
| 11199 | * Change the ICC password used in ICC pin lock. |
| 11200 | * |
| 11201 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11202 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11203 | * - Positive number and zero for remaining password attempts. |
| 11204 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11205 | * |
| 11206 | */ |
| 11207 | @Override |
| 11208 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11209 | enforceModifyPermission(); |
| 11210 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11211 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11212 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11213 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11214 | Phone phone = getPhone(subId); |
| 11215 | if (phone == null) { |
| 11216 | return 0; |
| 11217 | } |
| 11218 | // Now that all security checks passes, perform the operation as ourselves. |
| 11219 | final long identity = Binder.clearCallingIdentity(); |
| 11220 | try { |
| 11221 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11222 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11223 | return attemptsRemaining; |
| 11224 | |
| 11225 | } catch (Exception e) { |
| 11226 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11227 | } finally { |
| 11228 | Binder.restoreCallingIdentity(identity); |
| 11229 | } |
| 11230 | return 0; |
| 11231 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11232 | |
| 11233 | /** |
| 11234 | * Request for receiving user activity notification |
| 11235 | */ |
| 11236 | @Override |
| 11237 | public void requestUserActivityNotification() { |
| 11238 | if (!mNotifyUserActivity.get() |
| 11239 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11240 | mNotifyUserActivity.set(true); |
| 11241 | } |
| 11242 | } |
| 11243 | |
| 11244 | /** |
| 11245 | * Called when userActivity is signalled in the power manager. |
| 11246 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11247 | */ |
| 11248 | @Override |
| 11249 | public void userActivity() { |
| 11250 | // *************************************** |
| 11251 | // * Inherited from PhoneWindowManager * |
| 11252 | // *************************************** |
| 11253 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11254 | // WITH ITS LOCKS HELD. |
| 11255 | // |
| 11256 | // This code must be VERY careful about the locks |
| 11257 | // it acquires. |
| 11258 | // In fact, the current code acquires way too many, |
| 11259 | // and probably has lurking deadlocks. |
| 11260 | |
| 11261 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11262 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11263 | } |
| 11264 | |
| 11265 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11266 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11267 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11268 | } |
| 11269 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11270 | |
| 11271 | @Override |
| 11272 | public boolean canConnectTo5GInDsdsMode() { |
| 11273 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11274 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11275 | |
| 11276 | @Override |
| 11277 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11278 | String callingFeatureId) { |
| 11279 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11280 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11281 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11282 | } |
| 11283 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11284 | enforceTelephonyFeatureWithException(callingPackage, |
| 11285 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11286 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11287 | Phone phone = getPhone(subId); |
| 11288 | if (phone == null) { |
| 11289 | throw new RuntimeException("phone is not available"); |
| 11290 | } |
| 11291 | // Now that all security checks passes, perform the operation as ourselves. |
| 11292 | final long identity = Binder.clearCallingIdentity(); |
| 11293 | try { |
| 11294 | return phone.getEquivalentHomePlmns(); |
| 11295 | } finally { |
| 11296 | Binder.restoreCallingIdentity(identity); |
| 11297 | } |
| 11298 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11299 | |
| 11300 | @Override |
| 11301 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11302 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11303 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11304 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11305 | "isRadioInterfaceCapabilitySupported"); |
| 11306 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11307 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11308 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11309 | if (radioInterfaceCapabilities == null) { |
| 11310 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11311 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11312 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11313 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11314 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11315 | @Override |
| 11316 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11317 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11318 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11319 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11320 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11321 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11322 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11323 | |
| 11324 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11325 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11326 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11327 | if (DBG) { |
| 11328 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11329 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11330 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11331 | } |
| 11332 | |
| 11333 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11334 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11335 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11336 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11337 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11338 | if (callback != null) { |
| 11339 | try { |
| 11340 | callback.onAuthenticationFailure( |
| 11341 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11342 | } catch (RemoteException exception) { |
| 11343 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11344 | } |
| 11345 | return; |
| 11346 | } |
| 11347 | } |
| 11348 | |
| 11349 | final long token = Binder.clearCallingIdentity(); |
| 11350 | try { |
| 11351 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11352 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11353 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11354 | } finally { |
| 11355 | Binder.restoreCallingIdentity(token); |
| 11356 | } |
| 11357 | } |
| 11358 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11359 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11360 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11361 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11362 | * requested radio power state will actually be set. See {@link |
| 11363 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11364 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11365 | * @param enable {@code true} if trying to turn radio on. |
| 11366 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11367 | * false}. |
| 11368 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11369 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11370 | boolean isPhoneAvailable = false; |
| 11371 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11372 | Phone phone = PhoneFactory.getPhone(i); |
| 11373 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11374 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11375 | isPhoneAvailable = true; |
| 11376 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11377 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11378 | |
| 11379 | // return true if successfully informed the phone object about the thermal radio power |
| 11380 | // request. |
| 11381 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11382 | } |
| 11383 | |
| 11384 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11385 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11386 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11387 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11388 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11389 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11390 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11391 | } |
| 11392 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11393 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11394 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11395 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11396 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11397 | } |
| 11398 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11399 | setDataEnabledForReason( |
| 11400 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11401 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11402 | if (isDataThrottlingSupported) { |
| 11403 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11404 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11405 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11406 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11407 | } else if (thermalMitigationResult |
| 11408 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11409 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11410 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11411 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11412 | } |
| 11413 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11414 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11415 | |
| 11416 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11417 | } |
| 11418 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11419 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11420 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11421 | for (String pckg : context.getResources() |
| 11422 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11423 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11424 | } |
| 11425 | } |
| 11426 | |
| 11427 | return sThermalMitigationAllowlistedPackages; |
| 11428 | } |
| 11429 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11430 | private boolean isAnyPhoneInEmergencyState() { |
| 11431 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11432 | if (tm.isInEmergencyCall()) { |
| 11433 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11434 | return true; |
| 11435 | } |
| 11436 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11437 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11438 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11439 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11440 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11441 | return true; |
| 11442 | } |
| 11443 | } |
| 11444 | |
| 11445 | return false; |
| 11446 | } |
| 11447 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11448 | /** |
| 11449 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11450 | * @param packageName name of package to be allowlisted |
| 11451 | * @param context |
| 11452 | */ |
| 11453 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11454 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11455 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11456 | } |
| 11457 | |
| 11458 | /** |
| 11459 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11460 | * @param packageName name of package to remove from allowlist |
| 11461 | * @param context |
| 11462 | */ |
| 11463 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11464 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11465 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11466 | } |
| 11467 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11468 | /** |
| 11469 | * Thermal mitigation request to control functionalities at modem. |
| 11470 | * |
| 11471 | * @param subId the id of the subscription. |
| 11472 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11473 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11474 | * |
| 11475 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11476 | */ |
| 11477 | @Override |
| 11478 | @ThermalMitigationResult |
| 11479 | public int sendThermalMitigationRequest( |
| 11480 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11481 | ThermalMitigationRequest thermalMitigationRequest, |
| 11482 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11483 | enforceModifyPermission(); |
| 11484 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11485 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11486 | |
| 11487 | enforceTelephonyFeatureWithException(callingPackage, |
| 11488 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11489 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11490 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11491 | .contains(callingPackage)) { |
| 11492 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11493 | + "calling package: " + callingPackage); |
| 11494 | } |
| 11495 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11496 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11497 | final long identity = Binder.clearCallingIdentity(); |
| 11498 | |
| 11499 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11500 | try { |
| 11501 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11502 | switch (thermalMitigationAction) { |
| 11503 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11504 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11505 | handleDataThrottlingRequest(subId, |
| 11506 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11507 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11508 | break; |
| 11509 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11510 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11511 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11512 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11513 | } |
| 11514 | |
| 11515 | // Ensure that radio is on. If not able to power on due to phone being |
| 11516 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11517 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11518 | thermalMitigationResult = |
| 11519 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11520 | break; |
| 11521 | } |
| 11522 | |
| 11523 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11524 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11525 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11526 | break; |
| 11527 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11528 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11529 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11530 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11531 | } |
| 11532 | |
| 11533 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11534 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11535 | Phone phone = getPhone(subId); |
| 11536 | if (phone == null) { |
| 11537 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11538 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11539 | break; |
| 11540 | } |
| 11541 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11542 | TelephonyConnectionService service = |
| 11543 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11544 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11545 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11546 | thermalMitigationResult = |
| 11547 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11548 | break; |
| 11549 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11550 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11551 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11552 | break; |
| 11553 | } |
| 11554 | } else { |
| 11555 | thermalMitigationResult = |
| 11556 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11557 | break; |
| 11558 | } |
| 11559 | |
| 11560 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11561 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11562 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11563 | thermalMitigationResult = |
| 11564 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11565 | break; |
| 11566 | } |
| 11567 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11568 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11569 | break; |
| 11570 | default: |
| 11571 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11572 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11573 | } |
| 11574 | } catch (IllegalArgumentException e) { |
| 11575 | throw e; |
| 11576 | } catch (Exception e) { |
| 11577 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11578 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11579 | } finally { |
| 11580 | Binder.restoreCallingIdentity(identity); |
| 11581 | } |
| 11582 | |
| 11583 | if (DBG) { |
| 11584 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11585 | + thermalMitigationResult); |
| 11586 | } |
| 11587 | |
| 11588 | return thermalMitigationResult; |
| 11589 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11590 | |
| 11591 | /** |
| 11592 | * Set the GbaService Package Name that Telephony will bind to. |
| 11593 | * |
| 11594 | * @param subId The sim that the GbaService is associated with. |
| 11595 | * @param packageName The name of the package to be replaced with. |
| 11596 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11597 | */ |
| 11598 | @Override |
| 11599 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11600 | enforceModifyPermission(); |
| 11601 | |
| 11602 | final long identity = Binder.clearCallingIdentity(); |
| 11603 | try { |
| 11604 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11605 | } finally { |
| 11606 | Binder.restoreCallingIdentity(identity); |
| 11607 | } |
| 11608 | } |
| 11609 | |
| 11610 | /** |
| 11611 | * Return the package name of the currently bound GbaService. |
| 11612 | * |
| 11613 | * @param subId The sim that the GbaService is associated with. |
| 11614 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11615 | */ |
| 11616 | @Override |
| 11617 | public String getBoundGbaService(int subId) { |
| 11618 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11619 | |
| 11620 | final long identity = Binder.clearCallingIdentity(); |
| 11621 | try { |
| 11622 | return getGbaManager(subId).getServicePackage(); |
| 11623 | } finally { |
| 11624 | Binder.restoreCallingIdentity(identity); |
| 11625 | } |
| 11626 | } |
| 11627 | |
| 11628 | /** |
| 11629 | * Set the release time for telephony to unbind GbaService. |
| 11630 | * |
| 11631 | * @param subId The sim that the GbaService is associated with. |
| 11632 | * @param interval The release time to unbind GbaService by millisecond. |
| 11633 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11634 | */ |
| 11635 | @Override |
| 11636 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11637 | enforceModifyPermission(); |
| 11638 | |
| 11639 | final long identity = Binder.clearCallingIdentity(); |
| 11640 | try { |
| 11641 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11642 | } finally { |
| 11643 | Binder.restoreCallingIdentity(identity); |
| 11644 | } |
| 11645 | } |
| 11646 | |
| 11647 | /** |
| 11648 | * Return the release time for telephony to unbind GbaService. |
| 11649 | * |
| 11650 | * @param subId The sim that the GbaService is associated with. |
| 11651 | * @return The release time to unbind GbaService by millisecond. |
| 11652 | */ |
| 11653 | @Override |
| 11654 | public int getGbaReleaseTime(int subId) { |
| 11655 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11656 | |
| 11657 | final long identity = Binder.clearCallingIdentity(); |
| 11658 | try { |
| 11659 | return getGbaManager(subId).getReleaseTime(); |
| 11660 | } finally { |
| 11661 | Binder.restoreCallingIdentity(identity); |
| 11662 | } |
| 11663 | } |
| 11664 | |
| 11665 | private GbaManager getGbaManager(int subId) { |
| 11666 | GbaManager instance = GbaManager.getInstance(subId); |
| 11667 | if (instance == null) { |
| 11668 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11669 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11670 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11671 | } |
| 11672 | return instance; |
| 11673 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11674 | |
| 11675 | /** |
| 11676 | * indicate whether the device and the carrier can support |
| 11677 | * RCS VoLTE single registration. |
| 11678 | */ |
| 11679 | @Override |
| 11680 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11681 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11682 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11683 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11684 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11685 | |
| 11686 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11687 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11688 | } |
| 11689 | |
| 11690 | final long identity = Binder.clearCallingIdentity(); |
| 11691 | try { |
| 11692 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11693 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11694 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11695 | if (isCapable != null) { |
| 11696 | return isCapable; |
| 11697 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11698 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11699 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11700 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11701 | } finally { |
| 11702 | Binder.restoreCallingIdentity(identity); |
| 11703 | } |
| 11704 | } |
| 11705 | |
| 11706 | /** |
| 11707 | * Register RCS provisioning callback. |
| 11708 | */ |
| 11709 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11710 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11711 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11712 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11713 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11714 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11715 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11716 | |
| 11717 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11718 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11719 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11720 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11721 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11722 | Binder.getCallingUserHandle())) { |
| 11723 | if (!isImsAvailableOnDevice()) { |
| 11724 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11725 | "IMS not available on device."); |
| 11726 | } |
| 11727 | } else { |
| 11728 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11729 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11730 | } |
| 11731 | |
| 11732 | final long identity = Binder.clearCallingIdentity(); |
| 11733 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11734 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11735 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11736 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11737 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11738 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11739 | } finally { |
| 11740 | Binder.restoreCallingIdentity(identity); |
| 11741 | } |
| 11742 | } |
| 11743 | |
| 11744 | /** |
| 11745 | * Unregister RCS provisioning callback. |
| 11746 | */ |
| 11747 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11748 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11749 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11750 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11751 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11752 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11753 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11754 | |
| 11755 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11756 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11757 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11758 | |
| 11759 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11760 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11761 | Binder.getCallingUserHandle())) { |
| 11762 | if (!isImsAvailableOnDevice()) { |
| 11763 | // operation failed silently |
| 11764 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11765 | return; |
| 11766 | } |
| 11767 | } else { |
| 11768 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11769 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11770 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11771 | } |
| 11772 | |
| 11773 | final long identity = Binder.clearCallingIdentity(); |
| 11774 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11775 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11776 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11777 | } finally { |
| 11778 | Binder.restoreCallingIdentity(identity); |
| 11779 | } |
| 11780 | } |
| 11781 | |
| 11782 | /** |
| 11783 | * trigger RCS reconfiguration. |
| 11784 | */ |
| 11785 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11786 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11787 | "triggerRcsReconfiguration", |
| 11788 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11789 | |
| 11790 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11791 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11792 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11793 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11794 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11795 | Binder.getCallingUserHandle())) { |
| 11796 | if (!isImsAvailableOnDevice()) { |
| 11797 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11798 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11799 | throw new IllegalStateException("IMS not available on device."); |
| 11800 | } |
| 11801 | } else { |
| 11802 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11803 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11804 | } |
| 11805 | |
| 11806 | final long identity = Binder.clearCallingIdentity(); |
| 11807 | try { |
| 11808 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11809 | } finally { |
| 11810 | Binder.restoreCallingIdentity(identity); |
| 11811 | } |
| 11812 | } |
| 11813 | |
| 11814 | /** |
| 11815 | * Provide the client configuration parameters of the RCS application. |
| 11816 | */ |
| 11817 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11818 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11819 | "setRcsClientConfiguration", |
| 11820 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11821 | |
| 11822 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11823 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11824 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11825 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11826 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11827 | Binder.getCallingUserHandle())) { |
| 11828 | if (!isImsAvailableOnDevice()) { |
| 11829 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11830 | "IMS not available on device."); |
| 11831 | } |
| 11832 | } else { |
| 11833 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11834 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11835 | } |
| 11836 | |
| 11837 | final long identity = Binder.clearCallingIdentity(); |
| 11838 | |
| 11839 | try { |
| 11840 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11841 | if (configBinder == null) { |
| 11842 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11843 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11844 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11845 | } else { |
| 11846 | configBinder.setRcsClientConfiguration(rcc); |
| 11847 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11848 | |
| 11849 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11850 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11851 | } catch (RemoteException e) { |
| 11852 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11853 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11854 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11855 | } finally { |
| 11856 | Binder.restoreCallingIdentity(identity); |
| 11857 | } |
| 11858 | } |
| 11859 | |
| 11860 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11861 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11862 | */ |
| 11863 | @Override |
| 11864 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11865 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11866 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11867 | |
| 11868 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11869 | } |
| 11870 | |
| 11871 | /** |
| 11872 | * Gets the test mode for RCS VoLTE single registration. |
| 11873 | */ |
| 11874 | @Override |
| 11875 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11876 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11877 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11878 | |
| 11879 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11880 | } |
| 11881 | |
| 11882 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11883 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11884 | */ |
| 11885 | @Override |
| 11886 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11887 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11888 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11889 | enforceModifyPermission(); |
| 11890 | |
| 11891 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11892 | : Boolean.parseBoolean(enabledStr); |
| 11893 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11894 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11895 | } |
| 11896 | |
| 11897 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11898 | * Sends a device to device communication message. Only usable via shell. |
| 11899 | * @param message message to send. |
| 11900 | * @param value message value. |
| 11901 | */ |
| 11902 | @Override |
| 11903 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11904 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11905 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11906 | enforceModifyPermission(); |
| 11907 | |
| 11908 | final long identity = Binder.clearCallingIdentity(); |
| 11909 | try { |
| 11910 | TelephonyConnectionService service = |
| 11911 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11912 | if (service == null) { |
| 11913 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11914 | return; |
| 11915 | } |
| 11916 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11917 | } finally { |
| 11918 | Binder.restoreCallingIdentity(identity); |
| 11919 | } |
| 11920 | } |
| 11921 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11922 | /** |
| 11923 | * Sets the specified device to device transport active. |
| 11924 | * @param transport The transport to set active. |
| 11925 | */ |
| 11926 | @Override |
| 11927 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11928 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11929 | "setActiveDeviceToDeviceTransport"); |
| 11930 | enforceModifyPermission(); |
| 11931 | |
| 11932 | final long identity = Binder.clearCallingIdentity(); |
| 11933 | try { |
| 11934 | TelephonyConnectionService service = |
| 11935 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11936 | if (service == null) { |
| 11937 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11938 | return; |
| 11939 | } |
| 11940 | service.setActiveDeviceToDeviceTransport(transport); |
| 11941 | } finally { |
| 11942 | Binder.restoreCallingIdentity(identity); |
| 11943 | } |
| 11944 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11945 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11946 | @Override |
| 11947 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11948 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11949 | "setDeviceToDeviceForceEnabled"); |
| 11950 | |
| 11951 | final long identity = Binder.clearCallingIdentity(); |
| 11952 | try { |
| 11953 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11954 | p -> { |
| 11955 | Phone thePhone = p.getImsPhone(); |
| 11956 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11957 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11958 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11959 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11960 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11961 | (ImsPhoneCallTracker) tracker; |
| 11962 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11963 | } |
| 11964 | } |
| 11965 | } |
| 11966 | ); |
| 11967 | } finally { |
| 11968 | Binder.restoreCallingIdentity(identity); |
| 11969 | } |
| 11970 | } |
| 11971 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11972 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11973 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11974 | */ |
| 11975 | @Override |
| 11976 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11977 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11978 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11979 | } |
| 11980 | |
| 11981 | /** |
| 11982 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11983 | */ |
| 11984 | @Override |
| 11985 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11986 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11987 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11988 | enforceModifyPermission(); |
| 11989 | |
| 11990 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11991 | : Boolean.parseBoolean(enabledStr); |
| 11992 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11993 | subId, enabled); |
| 11994 | } |
| 11995 | |
| 11996 | /** |
| 11997 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11998 | */ |
| 11999 | @Override |
| 12000 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12001 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12002 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12003 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12004 | |
| 12005 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12006 | * Overrides the ims feature validation result |
| 12007 | */ |
| 12008 | @Override |
| 12009 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12010 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12011 | "setImsFeatureValidationOverride"); |
| 12012 | |
| 12013 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12014 | : Boolean.parseBoolean(enabledStr); |
| 12015 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12016 | subId, enabled); |
| 12017 | } |
| 12018 | |
| 12019 | /** |
| 12020 | * Gets the ims feature validation override value |
| 12021 | */ |
| 12022 | @Override |
| 12023 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12024 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12025 | "getImsFeatureValidationOverride"); |
| 12026 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12027 | } |
| 12028 | |
| 12029 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12030 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12031 | * their mobile plan. |
| 12032 | */ |
| 12033 | @Override |
| 12034 | public String getMobileProvisioningUrl() { |
| 12035 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12036 | final long identity = Binder.clearCallingIdentity(); |
| 12037 | try { |
| 12038 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12039 | } finally { |
| 12040 | Binder.restoreCallingIdentity(identity); |
| 12041 | } |
| 12042 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12043 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12044 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12045 | * Get the EAB contact from the EAB database. |
| 12046 | */ |
| 12047 | @Override |
| 12048 | public String getContactFromEab(String contact) { |
| 12049 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12050 | enforceModifyPermission(); |
| 12051 | final long identity = Binder.clearCallingIdentity(); |
| 12052 | try { |
| 12053 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12054 | } finally { |
| 12055 | Binder.restoreCallingIdentity(identity); |
| 12056 | } |
| 12057 | } |
| 12058 | |
| 12059 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12060 | * Get the EAB capability from the EAB database. |
| 12061 | */ |
| 12062 | @Override |
| 12063 | public String getCapabilityFromEab(String contact) { |
| 12064 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12065 | enforceModifyPermission(); |
| 12066 | final long identity = Binder.clearCallingIdentity(); |
| 12067 | try { |
| 12068 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12069 | } finally { |
| 12070 | Binder.restoreCallingIdentity(identity); |
| 12071 | } |
| 12072 | } |
| 12073 | |
| 12074 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12075 | * Remove the EAB contacts from the EAB database. |
| 12076 | */ |
| 12077 | @Override |
| 12078 | public int removeContactFromEab(int subId, String contacts) { |
| 12079 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12080 | enforceModifyPermission(); |
| 12081 | final long identity = Binder.clearCallingIdentity(); |
| 12082 | try { |
| 12083 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12084 | } finally { |
| 12085 | Binder.restoreCallingIdentity(identity); |
| 12086 | } |
| 12087 | } |
| 12088 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12089 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12090 | public boolean getDeviceUceEnabled() { |
| 12091 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12092 | final long identity = Binder.clearCallingIdentity(); |
| 12093 | try { |
| 12094 | return mApp.getDeviceUceEnabled(); |
| 12095 | } finally { |
| 12096 | Binder.restoreCallingIdentity(identity); |
| 12097 | } |
| 12098 | } |
| 12099 | |
| 12100 | @Override |
| 12101 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12102 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12103 | final long identity = Binder.clearCallingIdentity(); |
| 12104 | try { |
| 12105 | mApp.setDeviceUceEnabled(isEnabled); |
| 12106 | } finally { |
| 12107 | Binder.restoreCallingIdentity(identity); |
| 12108 | } |
| 12109 | } |
| 12110 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12111 | /** |
| 12112 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12113 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12114 | */ |
| 12115 | // Used for SHELL command only right now. |
| 12116 | @Override |
| 12117 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12118 | List<String> featureTags) { |
| 12119 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12120 | "addUceRegistrationOverrideShell"); |
| 12121 | final long identity = Binder.clearCallingIdentity(); |
| 12122 | try { |
| 12123 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12124 | new ArraySet<>(featureTags)); |
| 12125 | } catch (ImsException e) { |
| 12126 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12127 | } finally { |
| 12128 | Binder.restoreCallingIdentity(identity); |
| 12129 | } |
| 12130 | } |
| 12131 | |
| 12132 | /** |
| 12133 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12134 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12135 | */ |
| 12136 | // Used for SHELL command only right now. |
| 12137 | @Override |
| 12138 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12139 | List<String> featureTags) { |
| 12140 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12141 | "removeUceRegistrationOverrideShell"); |
| 12142 | final long identity = Binder.clearCallingIdentity(); |
| 12143 | try { |
| 12144 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12145 | new ArraySet<>(featureTags)); |
| 12146 | } catch (ImsException e) { |
| 12147 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12148 | } finally { |
| 12149 | Binder.restoreCallingIdentity(identity); |
| 12150 | } |
| 12151 | } |
| 12152 | |
| 12153 | /** |
| 12154 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12155 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12156 | */ |
| 12157 | // Used for SHELL command only right now. |
| 12158 | @Override |
| 12159 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12160 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12161 | "clearUceRegistrationOverrideShell"); |
| 12162 | final long identity = Binder.clearCallingIdentity(); |
| 12163 | try { |
| 12164 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12165 | } catch (ImsException e) { |
| 12166 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12167 | } finally { |
| 12168 | Binder.restoreCallingIdentity(identity); |
| 12169 | } |
| 12170 | } |
| 12171 | |
| 12172 | /** |
| 12173 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12174 | */ |
| 12175 | // Used for SHELL command only right now. |
| 12176 | @Override |
| 12177 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12178 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12179 | "getLatestRcsContactUceCapabilityShell"); |
| 12180 | final long identity = Binder.clearCallingIdentity(); |
| 12181 | try { |
| 12182 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12183 | } catch (ImsException e) { |
| 12184 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12185 | } finally { |
| 12186 | Binder.restoreCallingIdentity(identity); |
| 12187 | } |
| 12188 | } |
| 12189 | |
| 12190 | /** |
| 12191 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12192 | * device does not have an active PUBLISH. |
| 12193 | */ |
| 12194 | // Used for SHELL command only right now. |
| 12195 | @Override |
| 12196 | public String getLastUcePidfXmlShell(int subId) { |
| 12197 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12198 | final long identity = Binder.clearCallingIdentity(); |
| 12199 | try { |
| 12200 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12201 | } catch (ImsException e) { |
| 12202 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12203 | } finally { |
| 12204 | Binder.restoreCallingIdentity(identity); |
| 12205 | } |
| 12206 | } |
| 12207 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12208 | /** |
| 12209 | * Remove UCE requests cannot be sent to the network status. |
| 12210 | */ |
| 12211 | // Used for SHELL command only right now. |
| 12212 | @Override |
| 12213 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12214 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12215 | final long identity = Binder.clearCallingIdentity(); |
| 12216 | try { |
| 12217 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12218 | } catch (ImsException e) { |
| 12219 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12220 | } finally { |
| 12221 | Binder.restoreCallingIdentity(identity); |
| 12222 | } |
| 12223 | } |
| 12224 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12225 | /** |
| 12226 | * Remove UCE requests cannot be sent to the network status. |
| 12227 | */ |
| 12228 | // Used for SHELL command only. |
| 12229 | @Override |
| 12230 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12231 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12232 | final long identity = Binder.clearCallingIdentity(); |
| 12233 | try { |
| 12234 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12235 | } catch (ImsException e) { |
| 12236 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12237 | } finally { |
| 12238 | Binder.restoreCallingIdentity(identity); |
| 12239 | } |
| 12240 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12241 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12242 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12243 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12244 | String callingPackage) { |
| 12245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12246 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12247 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12248 | enforceTelephonyFeatureWithException(callingPackage, |
| 12249 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12250 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12251 | final int callingUid = Binder.getCallingUid(); |
| 12252 | // Verify that tha callingPackage belongs to the calling UID |
| 12253 | mApp.getSystemService(AppOpsManager.class) |
| 12254 | .checkPackage(callingUid, callingPackage); |
| 12255 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12256 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12257 | |
| 12258 | final long identity = Binder.clearCallingIdentity(); |
| 12259 | try { |
| 12260 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12261 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12262 | |
| 12263 | if (result instanceof IllegalStateException) { |
| 12264 | throw (IllegalStateException) result; |
| 12265 | } |
| 12266 | } finally { |
| 12267 | Binder.restoreCallingIdentity(identity); |
| 12268 | } |
| 12269 | } |
| 12270 | |
| 12271 | @Override |
| 12272 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12273 | String callingPackage) { |
| 12274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12275 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12276 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12277 | enforceTelephonyFeatureWithException(callingPackage, |
| 12278 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12279 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12280 | final int callingUid = Binder.getCallingUid(); |
| 12281 | // Verify that tha callingPackage belongs to the calling UID |
| 12282 | mApp.getSystemService(AppOpsManager.class) |
| 12283 | .checkPackage(callingUid, callingPackage); |
| 12284 | |
| 12285 | final long identity = Binder.clearCallingIdentity(); |
| 12286 | try { |
| 12287 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12288 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12289 | |
| 12290 | if (result instanceof IllegalStateException) { |
| 12291 | throw (IllegalStateException) result; |
| 12292 | } |
| 12293 | } finally { |
| 12294 | Binder.restoreCallingIdentity(identity); |
| 12295 | } |
| 12296 | } |
| 12297 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12298 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12299 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12300 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12301 | // phone/system process do not have further restriction on request |
| 12302 | return; |
| 12303 | } |
| 12304 | |
| 12305 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12306 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12307 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12308 | context.enforceCallingOrSelfPermission( |
| 12309 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12310 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12311 | } |
| 12312 | |
| 12313 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12314 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12315 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12316 | || info.isEnabled()) { |
| 12317 | throw new IllegalArgumentException( |
| 12318 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12319 | } |
| 12320 | |
| 12321 | // Thresholds length for each RAN need in range. This has been validated in |
| 12322 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12323 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12324 | final int[] thresholds = info.getThresholds(); |
| 12325 | Objects.requireNonNull(thresholds); |
| 12326 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12327 | || thresholds.length |
| 12328 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12329 | throw new IllegalArgumentException( |
| 12330 | "thresholds length is out of range: " + thresholds.length); |
| 12331 | } |
| 12332 | } |
| 12333 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12334 | |
| 12335 | /** |
| 12336 | * Gets the current phone capability. |
| 12337 | * |
| 12338 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12339 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12340 | * It's used to evaluate possible phone config change, for example from single |
| 12341 | * SIM device to multi-SIM device. |
| 12342 | */ |
| 12343 | @Override |
| 12344 | public PhoneCapability getPhoneCapability() { |
| 12345 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12346 | |
| 12347 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12348 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12349 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12350 | final long identity = Binder.clearCallingIdentity(); |
| 12351 | try { |
| 12352 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12353 | } finally { |
| 12354 | Binder.restoreCallingIdentity(identity); |
| 12355 | } |
| 12356 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12357 | |
| 12358 | /** |
| 12359 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12360 | * required to be done shortly after the API is invoked. |
| 12361 | */ |
| 12362 | @Override |
| 12363 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12364 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12365 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12366 | enforceRebootPermission(); |
| 12367 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12368 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12369 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12370 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12371 | final long identity = Binder.clearCallingIdentity(); |
| 12372 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12373 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12374 | } finally { |
| 12375 | Binder.restoreCallingIdentity(identity); |
| 12376 | } |
| 12377 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12378 | |
| 12379 | /** |
| 12380 | * Request to get the current slicing configuration including URSP rules and |
| 12381 | * NSSAIs (configured, allowed and rejected). |
| 12382 | * |
| 12383 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12384 | */ |
| 12385 | @Override |
| 12386 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12387 | TelephonyPermissions |
| 12388 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12389 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12390 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12391 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12392 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12393 | "getSlicingConfig"); |
| 12394 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12395 | final long identity = Binder.clearCallingIdentity(); |
| 12396 | try { |
| 12397 | Phone phone = getDefaultPhone(); |
| 12398 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12399 | } finally { |
| 12400 | Binder.restoreCallingIdentity(identity); |
| 12401 | } |
| 12402 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12403 | |
| 12404 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12405 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12406 | * |
| 12407 | * @param capability The premium capability to check. |
| 12408 | * @param subId The subId to check the premium capability for. |
| 12409 | * |
| 12410 | * @return Whether the given premium capability is available to purchase. |
| 12411 | */ |
| 12412 | @Override |
| 12413 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12414 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12415 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12416 | log("Premium capability " |
| 12417 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12418 | + " is not available for purchase due to missing permissions."); |
| 12419 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12420 | + "permission READ_BASIC_PHONE_STATE."); |
| 12421 | } |
| 12422 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12423 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12424 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12425 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12426 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12427 | if (phone == null) { |
| 12428 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12429 | return false; |
| 12430 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12431 | final long identity = Binder.clearCallingIdentity(); |
| 12432 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12433 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12434 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12435 | } finally { |
| 12436 | Binder.restoreCallingIdentity(identity); |
| 12437 | } |
| 12438 | } |
| 12439 | |
| 12440 | /** |
| 12441 | * Purchase the given premium capability from the carrier. |
| 12442 | * |
| 12443 | * @param capability The premium capability to purchase. |
| 12444 | * @param callback The result of the purchase request. |
| 12445 | * @param subId The subId to purchase the premium capability for. |
| 12446 | */ |
| 12447 | @Override |
| 12448 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12449 | log("purchasePremiumCapability: capability=" |
| 12450 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12451 | + getCurrentPackageName()); |
| 12452 | |
| 12453 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12454 | mApp, "purchasePremiumCapability")) { |
| 12455 | log("purchasePremiumCapability " |
| 12456 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12457 | + " failed due to missing permissions."); |
| 12458 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12459 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12460 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12461 | mApp, "purchasePremiumCapability")) { |
| 12462 | log("purchasePremiumCapability " |
| 12463 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12464 | + " failed due to missing permissions."); |
| 12465 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12466 | } |
| 12467 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12468 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12469 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12470 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12471 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12472 | if (phone == null) { |
| 12473 | try { |
| 12474 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12475 | callback.accept(result); |
| 12476 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12477 | } catch (RemoteException e) { |
| 12478 | String logStr = "Purchase premium capability " |
| 12479 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12480 | + " failed due to RemoteException handling null phone: " + e; |
| 12481 | if (DBG) log(logStr); |
| 12482 | AnomalyReporter.reportAnomaly( |
| 12483 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12484 | } |
| 12485 | return; |
| 12486 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12487 | |
| 12488 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12489 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12490 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12491 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12492 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12493 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12494 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12495 | |
| 12496 | boolean isVisible = false; |
| 12497 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12498 | if (am != null) { |
| 12499 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12500 | if (processes != null) { |
| 12501 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12502 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12503 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12504 | if (process.processName.equals(callingProcess) && process.importance |
| 12505 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12506 | isVisible = true; |
| 12507 | break; |
| 12508 | } |
| 12509 | } |
| 12510 | } |
| 12511 | } |
| 12512 | |
| 12513 | if (!isVisible) { |
| 12514 | try { |
| 12515 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12516 | callback.accept(result); |
| 12517 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12518 | } catch (RemoteException e) { |
| 12519 | String logStr = "Purchase premium capability " |
| 12520 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12521 | + " failed due to RemoteException handling background application: " + e; |
| 12522 | if (DBG) log(logStr); |
| 12523 | AnomalyReporter.reportAnomaly( |
| 12524 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12525 | } |
| 12526 | return; |
| 12527 | } |
| 12528 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12529 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12530 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12531 | } |
| 12532 | |
| 12533 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12534 | * Register an IMS connection state callback |
| 12535 | */ |
| 12536 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12537 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12538 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12539 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12540 | // ImsMmTelManager |
| 12541 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12542 | TelephonyPermissions |
| 12543 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12544 | mApp, subId, "registerImsStateCallback"); |
| 12545 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12546 | // ImsRcsManager or SipDelegateManager |
| 12547 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12548 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12549 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12550 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12551 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12552 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12553 | } |
| 12554 | |
| 12555 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12556 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12557 | "IMS not available on device."); |
| 12558 | } |
| 12559 | |
| 12560 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12561 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12562 | } |
| 12563 | |
| 12564 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12565 | if (controller == null) { |
| 12566 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12567 | "IMS not available on device."); |
| 12568 | } |
| 12569 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12570 | if (callingPackage == null) { |
| 12571 | callingPackage = getCurrentPackageName(); |
| 12572 | } |
| 12573 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12574 | final long token = Binder.clearCallingIdentity(); |
| 12575 | try { |
| 12576 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12577 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12578 | } catch (ImsException e) { |
| 12579 | throw new ServiceSpecificException(e.getCode()); |
| 12580 | } finally { |
| 12581 | Binder.restoreCallingIdentity(token); |
| 12582 | } |
| 12583 | } |
| 12584 | |
| 12585 | /** |
| 12586 | * Unregister an IMS connection state callback |
| 12587 | */ |
| 12588 | @Override |
| 12589 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12590 | final long token = Binder.clearCallingIdentity(); |
| 12591 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12592 | if (controller == null) { |
| 12593 | return; |
| 12594 | } |
| 12595 | try { |
| 12596 | controller.unregisterImsStateCallback(cb); |
| 12597 | } finally { |
| 12598 | Binder.restoreCallingIdentity(token); |
| 12599 | } |
| 12600 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12601 | |
| 12602 | /** |
| 12603 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12604 | * |
| 12605 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12606 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12607 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12608 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12609 | * If there is current registered network this value will be same as the registered cell |
| 12610 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12611 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12612 | * it will be cleared and null will be returned. |
| 12613 | * |
| 12614 | */ |
| 12615 | @Override |
| 12616 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12617 | String callingFeatureId) { |
| 12618 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12619 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12620 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12621 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12622 | .setCallingPackage(callingPackage) |
| 12623 | .setCallingFeatureId(callingFeatureId) |
| 12624 | .setCallingPid(Binder.getCallingPid()) |
| 12625 | .setCallingUid(Binder.getCallingUid()) |
| 12626 | .setMethod("getLastKnownCellIdentity") |
| 12627 | .setLogAsInfo(true) |
| 12628 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12629 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12630 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12631 | .build()); |
| 12632 | |
| 12633 | boolean hasFinePermission = |
| 12634 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12635 | if (!hasFinePermission |
| 12636 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12637 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12638 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12639 | } |
| 12640 | |
| 12641 | final long identity = Binder.clearCallingIdentity(); |
| 12642 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12643 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12644 | if (sst == null) return null; |
| 12645 | return sst.getLastKnownCellIdentity(); |
| 12646 | } finally { |
| 12647 | Binder.restoreCallingIdentity(identity); |
| 12648 | } |
| 12649 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12650 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12651 | /** |
| 12652 | * Sets the modem service class Name that Telephony will bind to. |
| 12653 | * |
| 12654 | * @param serviceName The class name of the modem service. |
| 12655 | * @return true if the operation is succeed, otherwise false. |
| 12656 | */ |
| 12657 | public boolean setModemService(String serviceName) { |
| 12658 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12659 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12661 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12662 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12663 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12664 | } |
| 12665 | |
| 12666 | /** |
| 12667 | * Return the class name of the currently bounded modem service. |
| 12668 | * |
| 12669 | * @return the class name of the modem service. |
| 12670 | */ |
| 12671 | public String getModemService() { |
| 12672 | String result; |
| 12673 | Log.d(LOG_TAG, "getModemService"); |
| 12674 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12675 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12676 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12677 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12678 | "getModemService"); |
| 12679 | result = mPhoneConfigurationManager.getModemService(); |
| 12680 | Log.d(LOG_TAG, "result = " + result); |
| 12681 | return result; |
| 12682 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12683 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12684 | /** |
| 12685 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12686 | * including carrier config, entitlement server, and config update. |
| 12687 | * |
| 12688 | * @param subId subId The subscription ID of the carrier. |
| 12689 | * |
| 12690 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12691 | * be returned. |
| 12692 | * |
| 12693 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12694 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12695 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12696 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12697 | final long identity = Binder.clearCallingIdentity(); |
| 12698 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12699 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12700 | } finally { |
| 12701 | Binder.restoreCallingIdentity(identity); |
| 12702 | } |
| 12703 | } |
| 12704 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12705 | @Override |
| 12706 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12707 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12708 | mApp.enforceCallingOrSelfPermission( |
| 12709 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12710 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12711 | |
| 12712 | final long identity = Binder.clearCallingIdentity(); |
| 12713 | try { |
| 12714 | Phone phone = getPhone(subId); |
| 12715 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12716 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12717 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12718 | phone.setVoiceServiceStateOverride(hasService); |
| 12719 | } finally { |
| 12720 | Binder.restoreCallingIdentity(identity); |
| 12721 | } |
| 12722 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12723 | |
| 12724 | /** |
| 12725 | * set removable eSIM as default eUICC. |
| 12726 | * |
| 12727 | * @hide |
| 12728 | */ |
| 12729 | @Override |
| 12730 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12731 | enforceModifyPermission(); |
| 12732 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12733 | |
| 12734 | final long identity = Binder.clearCallingIdentity(); |
| 12735 | try { |
| 12736 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12737 | } finally { |
| 12738 | Binder.restoreCallingIdentity(identity); |
| 12739 | } |
| 12740 | } |
| 12741 | |
| 12742 | /** |
| 12743 | * Returns whether the removable eSIM is default eUICC or not. |
| 12744 | * |
| 12745 | * @hide |
| 12746 | */ |
| 12747 | @Override |
| 12748 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12749 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12750 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12751 | |
| 12752 | final long identity = Binder.clearCallingIdentity(); |
| 12753 | try { |
| 12754 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12755 | } finally { |
| 12756 | Binder.restoreCallingIdentity(identity); |
| 12757 | } |
| 12758 | } |
| 12759 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12760 | /** |
| 12761 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12762 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12763 | * application currently configured for this user. |
| 12764 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12765 | * {@code null} if the functionality is not supported. |
| 12766 | * @hide |
| 12767 | */ |
| 12768 | @Override |
| 12769 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12770 | boolean updateIfNeeded) { |
| 12771 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12772 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12773 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12774 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12775 | "getDefaultRespondViaMessageApplication"); |
| 12776 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12777 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12778 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12779 | UserHandle userHandle = null; |
| 12780 | final long identity = Binder.clearCallingIdentity(); |
| 12781 | try { |
| 12782 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12783 | } finally { |
| 12784 | Binder.restoreCallingIdentity(identity); |
| 12785 | } |
| 12786 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12787 | updateIfNeeded, userHandle); |
| 12788 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12789 | |
| 12790 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12791 | * Set whether the device is able to connect with null ciphering or integrity |
| 12792 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12793 | * and all new subscriptions after this. |
| 12794 | * |
| 12795 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12796 | * @hide |
| 12797 | */ |
| 12798 | @Override |
| 12799 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12800 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12801 | enforceModifyPermission(); |
| 12802 | checkForNullCipherAndIntegritySupport(); |
| 12803 | |
| 12804 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12805 | // for listening to these preference changes and applying them immediately. |
| 12806 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12807 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12808 | editor.apply(); |
| 12809 | |
| 12810 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12811 | phone.handleNullCipherEnabledChange(); |
| 12812 | } |
| 12813 | } |
| 12814 | |
| 12815 | |
| 12816 | /** |
| 12817 | * Get whether the device is able to connect with null ciphering or integrity |
| 12818 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12819 | * the state of the radio. |
| 12820 | * |
| 12821 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12822 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12823 | * version for this feature. |
| 12824 | * @hide |
| 12825 | */ |
| 12826 | @Override |
| 12827 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12828 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12829 | enforceReadPermission(); |
| 12830 | checkForNullCipherAndIntegritySupport(); |
| 12831 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12832 | } |
| 12833 | |
| 12834 | private void checkForNullCipherAndIntegritySupport() { |
| 12835 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12836 | throw new UnsupportedOperationException( |
| 12837 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12838 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12839 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12840 | throw new UnsupportedOperationException( |
| 12841 | "Null cipher and integrity operations unsupported by modem"); |
| 12842 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12843 | } |
| 12844 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12845 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12846 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12847 | throw new UnsupportedOperationException( |
| 12848 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12849 | + "above"); |
| 12850 | } |
| 12851 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12852 | throw new UnsupportedOperationException( |
| 12853 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12854 | } |
| 12855 | } |
| 12856 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12857 | private void checkForNullCipherNotificationSupport() { |
| 12858 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12859 | throw new UnsupportedOperationException( |
| 12860 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12861 | } |
| 12862 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12863 | throw new UnsupportedOperationException( |
| 12864 | "Null cipher notification operations unsupported by modem"); |
| 12865 | } |
| 12866 | } |
| 12867 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12868 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12869 | * Get the SIM state for the slot index. |
| 12870 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12871 | * |
| 12872 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12873 | */ |
| 12874 | @Override |
| 12875 | @SimState |
| 12876 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12877 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12878 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12879 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12880 | IccCardConstants.State simState; |
| 12881 | if (slotIndex < 0) { |
| 12882 | simState = IccCardConstants.State.UNKNOWN; |
| 12883 | } else { |
| 12884 | Phone phone = null; |
| 12885 | try { |
| 12886 | phone = PhoneFactory.getPhone(slotIndex); |
| 12887 | } catch (IllegalStateException e) { |
| 12888 | // ignore |
| 12889 | } |
| 12890 | if (phone == null) { |
| 12891 | simState = IccCardConstants.State.UNKNOWN; |
| 12892 | } else { |
| 12893 | IccCard icc = phone.getIccCard(); |
| 12894 | if (icc == null) { |
| 12895 | simState = IccCardConstants.State.UNKNOWN; |
| 12896 | } else { |
| 12897 | simState = icc.getState(); |
| 12898 | } |
| 12899 | } |
| 12900 | } |
| 12901 | return simState.ordinal(); |
| 12902 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12903 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12904 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12905 | boolean enableLogcat, |
| 12906 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12907 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12908 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12909 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12910 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12911 | ecdDataBuilder |
| 12912 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12913 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12914 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12915 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12916 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12917 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12918 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12919 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12920 | Executors.newCachedThreadPool(), db, |
| 12921 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12922 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12923 | } |
| 12924 | |
| 12925 | /** |
| 12926 | * Request telephony to persist state for debugging emergency call failures. |
| 12927 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12928 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12929 | * @param enableLogcat whether to collect logcat output |
| 12930 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12931 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12932 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12933 | */ |
| 12934 | @Override |
| 12935 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12936 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12937 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12938 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 12939 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 12940 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 12941 | && Flags.enableReadDropboxPermission()) { |
| 12942 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 12943 | "persistEmergencyCallDiagnosticData"); |
| 12944 | } else { |
| 12945 | // Otherwise, enforce legacy permission. |
| 12946 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12947 | "persistEmergencyCallDiagnosticData"); |
| 12948 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12949 | final long identity = Binder.clearCallingIdentity(); |
| 12950 | try { |
| 12951 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12952 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12953 | |
| 12954 | } finally { |
| 12955 | Binder.restoreCallingIdentity(identity); |
| 12956 | } |
| 12957 | } |
| 12958 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12959 | /** |
| 12960 | * Get current cell broadcast ranges. |
| 12961 | */ |
| 12962 | @Override |
| 12963 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12964 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12965 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12966 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12967 | |
| 12968 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12969 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12970 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12971 | final long identity = Binder.clearCallingIdentity(); |
| 12972 | try { |
| 12973 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12974 | } finally { |
| 12975 | Binder.restoreCallingIdentity(identity); |
| 12976 | } |
| 12977 | } |
| 12978 | |
| 12979 | /** |
| 12980 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12981 | * |
| 12982 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12983 | */ |
| 12984 | @Override |
| 12985 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12986 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12987 | @Nullable IIntegerConsumer callback) { |
| 12988 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12989 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12990 | |
| 12991 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12992 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12993 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12994 | final long identity = Binder.clearCallingIdentity(); |
| 12995 | try { |
| 12996 | Phone phone = getPhoneFromSubId(subId); |
| 12997 | if (DBG) { |
| 12998 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12999 | } |
| 13000 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13001 | if (callback != null) { |
| 13002 | try { |
| 13003 | callback.accept(result); |
| 13004 | } catch (RemoteException e) { |
| 13005 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13006 | } |
| 13007 | } |
| 13008 | }); |
| 13009 | } finally { |
| 13010 | Binder.restoreCallingIdentity(identity); |
| 13011 | } |
| 13012 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13013 | |
| 13014 | /** |
| 13015 | * Returns whether the device supports the domain selection service. |
| 13016 | * |
| 13017 | * @return {@code true} if the device supports the domain selection service. |
| 13018 | */ |
| 13019 | @Override |
| 13020 | public boolean isDomainSelectionSupported() { |
| 13021 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13022 | "isDomainSelectionSupported"); |
| 13023 | |
| 13024 | final long identity = Binder.clearCallingIdentity(); |
| 13025 | try { |
| 13026 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13027 | } finally { |
| 13028 | Binder.restoreCallingIdentity(identity); |
| 13029 | } |
| 13030 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13031 | |
| 13032 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13033 | * Returns whether the AOSP domain selection service is supported. |
| 13034 | * |
| 13035 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13036 | * {@code false} otherwise. |
| 13037 | */ |
| 13038 | @Override |
| 13039 | public boolean isAospDomainSelectionService() { |
| 13040 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13041 | "isAospDomainSelectionService"); |
| 13042 | |
| 13043 | final long identity = Binder.clearCallingIdentity(); |
| 13044 | try { |
| 13045 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13046 | String dssComponentName = mApp.getResources().getString( |
| 13047 | R.string.config_domain_selection_service_component_name); |
| 13048 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13049 | TelephonyDomainSelectionService.class.getName()); |
| 13050 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13051 | + ", aosp=" + componentName.flattenToString()); |
| 13052 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13053 | } |
| 13054 | } finally { |
| 13055 | Binder.restoreCallingIdentity(identity); |
| 13056 | } |
| 13057 | return false; |
| 13058 | } |
| 13059 | |
| 13060 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13061 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13062 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13063 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13064 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13065 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13066 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13067 | * {@code false} to disable. |
| 13068 | * @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] | 13069 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13070 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13071 | * |
| 13072 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13073 | */ |
| 13074 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13075 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13076 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13077 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13078 | if (enableSatellite) { |
| 13079 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13080 | @Override |
| 13081 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13082 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13083 | + ", resultData=" + resultData); |
| 13084 | boolean isAllowed = false; |
| 13085 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13086 | callback::accept); |
| 13087 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13088 | if (resultData != null |
| 13089 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13090 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13091 | } else { |
| 13092 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13093 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13094 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13095 | result.accept(resultCode); |
| 13096 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13097 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13098 | if (isAllowed) { |
| 13099 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13100 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13101 | } else { |
| 13102 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13103 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13104 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13105 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13106 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13107 | subId, resultReceiver); |
| 13108 | } else { |
| 13109 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13110 | mSatelliteController.requestSatelliteEnabled( |
Hyosun Kim | ab30479 | 2024-03-29 09:18:03 +0000 | [diff] [blame] | 13111 | subId, enableSatellite, enableDemoMode, isEmergency, callback); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13112 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13113 | } |
| 13114 | |
| 13115 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13116 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13117 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13118 | * @param subId The subId of the subscription to check whether satellite is enabled for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13119 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13120 | * 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] | 13121 | * |
| 13122 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13123 | */ |
| 13124 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13125 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13126 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13127 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13128 | } |
| 13129 | |
| 13130 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13131 | * Request to get whether the satellite service demo mode is enabled. |
| 13132 | * |
| 13133 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13134 | * is enabled for. |
| 13135 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13136 | * if the request is successful or an error code if the request failed. |
| 13137 | * |
| 13138 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13139 | */ |
| 13140 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13141 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13142 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13143 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13144 | } |
| 13145 | |
| 13146 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13147 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13148 | * |
| 13149 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13150 | * is enabled for. |
| 13151 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13152 | * enabled if the request is successful or an error code if the request failed. |
| 13153 | * |
| 13154 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13155 | */ |
| 13156 | @Override |
| 13157 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13158 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
| 13159 | result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null); |
| 13160 | } |
| 13161 | |
| 13162 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13163 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13164 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13165 | * @param subId The subId of the subscription to check satellite service support for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13166 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13167 | * 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] | 13168 | */ |
| 13169 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13170 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13171 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13172 | } |
| 13173 | |
| 13174 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13175 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13176 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13177 | * @param subId The subId of the subscription to get the satellite capabilities for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13178 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13179 | * 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] | 13180 | * |
| 13181 | * @throws SecurityException if the caller doesn't have required permission. |
| 13182 | */ |
| 13183 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13184 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13185 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13186 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13187 | } |
| 13188 | |
| 13189 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13190 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13191 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13192 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13193 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13194 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13195 | * @param resultCallback The callback to get the result of the request. |
| 13196 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13197 | * |
| 13198 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13199 | */ |
| 13200 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13201 | public void startSatelliteTransmissionUpdates(int subId, |
| 13202 | @NonNull IIntegerConsumer resultCallback, |
| 13203 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13204 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13205 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13206 | } |
| 13207 | |
| 13208 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13209 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13210 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13211 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13212 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13213 | * @param resultCallback The callback to get the result of the request. |
| 13214 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13215 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13216 | * |
| 13217 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13218 | */ |
| 13219 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13220 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13221 | @NonNull IIntegerConsumer resultCallback, |
| 13222 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13223 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13224 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13225 | } |
| 13226 | |
| 13227 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13228 | * Register the subscription with a satellite provider. |
| 13229 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13230 | * |
| 13231 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13232 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13233 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13234 | * @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] | 13235 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13236 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13237 | * @return The signal transport used by the caller to cancel the provision request, |
| 13238 | * or {@code null} if the request failed. |
| 13239 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13240 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13241 | */ |
| 13242 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13243 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13244 | @NonNull String token, @NonNull byte[] provisionData, |
| 13245 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13246 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13247 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13248 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13249 | } |
| 13250 | |
| 13251 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13252 | * Unregister the device/subscription with the satellite provider. |
| 13253 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13254 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13255 | * should report as deprovisioned. |
| 13256 | * |
| 13257 | * @param subId The subId of the subscription to be deprovisioned. |
| 13258 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13259 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13260 | * |
| 13261 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13262 | */ |
| 13263 | @Override |
| 13264 | public void deprovisionSatelliteService(int subId, |
| 13265 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13266 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13267 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13268 | } |
| 13269 | |
| 13270 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13271 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13272 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13273 | * @param subId The subId of the subscription to register for provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13274 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13275 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13276 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13277 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13278 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13279 | */ |
| 13280 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13281 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13282 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13283 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13284 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13285 | } |
| 13286 | |
| 13287 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13288 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13289 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13290 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13291 | * @param subId The subId of the subscription to unregister for provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13292 | * @param callback The callback that was passed to |
| 13293 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13294 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13295 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13296 | */ |
| 13297 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13298 | public void unregisterForSatelliteProvisionStateChanged( |
| 13299 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13300 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13301 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13302 | } |
| 13303 | |
| 13304 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13305 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13306 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13307 | * @param subId The subId of the subscription to get whether the device is provisioned for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13308 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13309 | * satellite provider if the request is successful or an error code if the |
| 13310 | * request failed. |
| 13311 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13312 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13313 | */ |
| 13314 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13315 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13316 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13317 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13318 | } |
| 13319 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13320 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13321 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13322 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13323 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13324 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13325 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13326 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13327 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13328 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13329 | */ |
| 13330 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13331 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13332 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13333 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13334 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13335 | } |
| 13336 | |
| 13337 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13338 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13339 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13340 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13341 | * @param subId The subId of the subscription to unregister for satellite modem state changed. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13342 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13343 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13344 | * |
| 13345 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13346 | */ |
| 13347 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13348 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13349 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13350 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13351 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13352 | } |
| 13353 | |
| 13354 | /** |
| 13355 | * Register to receive incoming datagrams over satellite. |
| 13356 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13357 | * @param subId The subId of the subscription to register for incoming satellite datagrams. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13358 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13359 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13360 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13361 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13362 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13363 | */ |
| 13364 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13365 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13366 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13367 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13368 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13369 | } |
| 13370 | |
| 13371 | /** |
| 13372 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13373 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13374 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13375 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13376 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13377 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13378 | * |
| 13379 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13380 | */ |
| 13381 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13382 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13383 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13384 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13385 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13386 | } |
| 13387 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13388 | /** |
| 13389 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13390 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13391 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13392 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13393 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13394 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13395 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13396 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13397 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13398 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13399 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13400 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13401 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13402 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13403 | } |
| 13404 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13405 | /** |
| 13406 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13407 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13408 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13409 | * input to this method. Datagram received here will be passed down to modem without any |
| 13410 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13411 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13412 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13413 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13414 | * SOS_SMS or LOCATION_SHARING. |
| 13415 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13416 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13417 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13418 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13419 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13420 | * |
| 13421 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13422 | */ |
| 13423 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13424 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13425 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13426 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13427 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13428 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13429 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13430 | } |
| 13431 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13432 | /** |
| 13433 | * Request to get whether satellite communication is allowed for the current location. |
| 13434 | * |
| 13435 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13436 | * allowed for the current location for. |
| 13437 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13438 | * for the current location if the request is successful or an error code |
| 13439 | * if the request failed. |
| 13440 | * |
| 13441 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13442 | */ |
| 13443 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13444 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13445 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13446 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13447 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13448 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13449 | } |
| 13450 | |
| 13451 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13452 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13453 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13454 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13455 | * @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] | 13456 | * be visible if the request is successful or an error code if the request failed. |
| 13457 | * |
| 13458 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13459 | */ |
| 13460 | @Override |
| 13461 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13462 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13463 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13464 | } |
| 13465 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13466 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13467 | * Inform that Device is aligned to satellite for demo mode. |
| 13468 | * |
| 13469 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13470 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13471 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13472 | * |
| 13473 | * @throws SecurityException if the caller doesn't have required permission. |
| 13474 | */ |
| 13475 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13476 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13477 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13478 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13479 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13480 | } |
| 13481 | |
| 13482 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13483 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13484 | * by modem. |
| 13485 | * |
| 13486 | * @param subId The subId of the subscription to request for. |
| 13487 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13488 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13489 | * operation. |
| 13490 | * |
| 13491 | * @throws SecurityException if the caller doesn't have required permission. |
| 13492 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13493 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13494 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13495 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13496 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13497 | final long identity = Binder.clearCallingIdentity(); |
| 13498 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13499 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13500 | } finally { |
| 13501 | Binder.restoreCallingIdentity(identity); |
| 13502 | } |
| 13503 | } |
| 13504 | |
| 13505 | /** |
| 13506 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13507 | * by modem. |
| 13508 | * |
| 13509 | * @param subId The subId of the subscription to request for. |
| 13510 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13511 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13512 | * operation. |
| 13513 | * |
| 13514 | * @throws SecurityException if the caller doesn't have required permission. |
| 13515 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13516 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13517 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13518 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13519 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13520 | final long identity = Binder.clearCallingIdentity(); |
| 13521 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13522 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13523 | } finally { |
| 13524 | Binder.restoreCallingIdentity(identity); |
| 13525 | } |
| 13526 | } |
| 13527 | |
| 13528 | /** |
| 13529 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13530 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13531 | * |
| 13532 | * @param subId The subId of the subscription to request for. |
| 13533 | * |
| 13534 | * @return Integer array of reasons for disallowing satellite communication. |
| 13535 | * |
| 13536 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13537 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13538 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13539 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13540 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13541 | final long identity = Binder.clearCallingIdentity(); |
| 13542 | try { |
| 13543 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13544 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13545 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13546 | } finally { |
| 13547 | Binder.restoreCallingIdentity(identity); |
| 13548 | } |
| 13549 | } |
| 13550 | |
| 13551 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13552 | * Request to get the signal strength of the satellite connection. |
| 13553 | * |
| 13554 | * @param subId The subId of the subscription to request for. |
| 13555 | * @param result Result receiver to get the error code of the request and the current signal |
| 13556 | * strength of the satellite connection. |
| 13557 | * |
| 13558 | * @throws SecurityException if the caller doesn't have required permission. |
| 13559 | */ |
| 13560 | @Override |
| 13561 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13562 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13563 | final long identity = Binder.clearCallingIdentity(); |
| 13564 | try { |
| 13565 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13566 | } finally { |
| 13567 | Binder.restoreCallingIdentity(identity); |
| 13568 | } |
| 13569 | } |
| 13570 | |
| 13571 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13572 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13573 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13574 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13575 | * |
| 13576 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13577 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13578 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13579 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13580 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13581 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13582 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13583 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13584 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13585 | */ |
| 13586 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13587 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13588 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13589 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13590 | final long identity = Binder.clearCallingIdentity(); |
| 13591 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13592 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13593 | } finally { |
| 13594 | Binder.restoreCallingIdentity(identity); |
| 13595 | } |
| 13596 | } |
| 13597 | |
| 13598 | /** |
| 13599 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13600 | * If callback was not registered before, the request will be ignored. |
| 13601 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13602 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13603 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13604 | * @param callback The callback that was passed to |
| 13605 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13606 | * |
| 13607 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13608 | */ |
| 13609 | @Override |
| 13610 | public void unregisterForNtnSignalStrengthChanged( |
| 13611 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13612 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13613 | final long identity = Binder.clearCallingIdentity(); |
| 13614 | try { |
| 13615 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13616 | } finally { |
| 13617 | Binder.restoreCallingIdentity(identity); |
| 13618 | } |
| 13619 | } |
| 13620 | |
| 13621 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13622 | * Registers for satellite capabilities change event from the satellite service. |
| 13623 | * |
| 13624 | * @param subId The subId of the subscription to request for. |
| 13625 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13626 | * |
| 13627 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13628 | * |
| 13629 | * @throws SecurityException if the caller doesn't have required permission. |
| 13630 | */ |
| 13631 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13632 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13633 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13634 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13635 | final long identity = Binder.clearCallingIdentity(); |
| 13636 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13637 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13638 | } finally { |
| 13639 | Binder.restoreCallingIdentity(identity); |
| 13640 | } |
| 13641 | } |
| 13642 | |
| 13643 | /** |
| 13644 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13645 | * If callback was not registered before, the request will be ignored. |
| 13646 | * |
| 13647 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13648 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13649 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13650 | * |
| 13651 | * @throws SecurityException if the caller doesn't have required permission. |
| 13652 | */ |
| 13653 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13654 | public void unregisterForCapabilitiesChanged(int subId, |
| 13655 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13656 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13657 | final long identity = Binder.clearCallingIdentity(); |
| 13658 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13659 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13660 | } finally { |
| 13661 | Binder.restoreCallingIdentity(identity); |
| 13662 | } |
| 13663 | } |
| 13664 | |
| 13665 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13666 | * Registers for the satellite supported state changed. |
| 13667 | * |
| 13668 | * @param subId The subId of the subscription to register for supported state changed. |
| 13669 | * @param callback The callback to handle the satellite supported state changed event. |
| 13670 | * |
| 13671 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13672 | * |
| 13673 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13674 | */ |
| 13675 | @Override |
| 13676 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
| 13677 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13678 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
| 13679 | return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback); |
| 13680 | } |
| 13681 | |
| 13682 | /** |
| 13683 | * Unregisters for the satellite supported state changed. |
| 13684 | * If callback was not registered before, the request will be ignored. |
| 13685 | * |
| 13686 | * @param subId The subId of the subscription to unregister for supported state changed. |
| 13687 | * @param callback The callback that was passed to |
| 13688 | * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}. |
| 13689 | * |
| 13690 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13691 | */ |
| 13692 | @Override |
| 13693 | public void unregisterForSatelliteSupportedStateChanged( |
| 13694 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13695 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
| 13696 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback); |
| 13697 | } |
| 13698 | |
| 13699 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13700 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13701 | * |
| 13702 | * @param servicePackageName The package name of the satellite vendor service. |
| 13703 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13704 | * {@code false} otherwise. |
| 13705 | */ |
| 13706 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13707 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13708 | TelephonyPermissions.enforceShellOnly( |
| 13709 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13710 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13711 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13712 | "setSatelliteServicePackageName"); |
| 13713 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13714 | } |
| 13715 | |
| 13716 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13717 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13718 | * |
| 13719 | * @param servicePackageName The package name of the satellite gateway service. |
| 13720 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13721 | * {@code false} otherwise. |
| 13722 | */ |
| 13723 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13724 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13725 | TelephonyPermissions.enforceShellOnly( |
| 13726 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13728 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13729 | "setSatelliteGatewayServicePackageName"); |
| 13730 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13731 | } |
| 13732 | |
| 13733 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13734 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13735 | * |
| 13736 | * @param packageName The package name of the satellite pointing UI app. |
| 13737 | * @param className The class name of the satellite pointing UI app. |
| 13738 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13739 | * {@code false} otherwise. |
| 13740 | */ |
| 13741 | public boolean setSatellitePointingUiClassName( |
| 13742 | @Nullable String packageName, @Nullable String className) { |
| 13743 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13744 | + ", className=" + className); |
| 13745 | TelephonyPermissions.enforceShellOnly( |
| 13746 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13748 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13749 | "setSatelliteGatewayServicePackageName"); |
| 13750 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13751 | } |
| 13752 | |
| 13753 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13754 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13755 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13756 | * listening mode. |
| 13757 | * |
| 13758 | * @param timeoutMillis The timeout duration in millisecond. |
| 13759 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13760 | */ |
| 13761 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13762 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13763 | TelephonyPermissions.enforceShellOnly( |
| 13764 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13766 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13767 | "setSatelliteListeningTimeoutDuration"); |
| 13768 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13769 | } |
| 13770 | |
| 13771 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13772 | * This API can be used by only CTS to override the timeout durations used by the |
| 13773 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13774 | * |
| 13775 | * @param timeoutMillis The timeout duration in millisecond. |
| 13776 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13777 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13778 | public boolean setDatagramControllerTimeoutDuration( |
| 13779 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13780 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13781 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13782 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13783 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13785 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13786 | "setDatagramControllerTimeoutDuration"); |
| 13787 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13788 | reset, timeoutType, timeoutMillis); |
| 13789 | } |
| 13790 | |
| 13791 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 13792 | * This API can be used by only CTS to override the boolean configs used by the |
| 13793 | * DatagramController module. |
| 13794 | * |
| 13795 | * @param enable Whether to enable or disable boolean config. |
| 13796 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 13797 | */ |
| 13798 | public boolean setDatagramControllerBooleanConfig( |
| 13799 | boolean reset, int booleanType, boolean enable) { |
| 13800 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 13801 | + ", reset=" + reset + ", enable=" + enable); |
| 13802 | TelephonyPermissions.enforceShellOnly( |
| 13803 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 13804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13805 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13806 | "ssetDatagramControllerBooleanConfig"); |
| 13807 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable); |
| 13808 | } |
| 13809 | |
| 13810 | |
| 13811 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13812 | * This API can be used by only CTS to override the timeout durations used by the |
| 13813 | * SatelliteController module. |
| 13814 | * |
| 13815 | * @param timeoutMillis The timeout duration in millisecond. |
| 13816 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13817 | */ |
| 13818 | public boolean setSatelliteControllerTimeoutDuration( |
| 13819 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13820 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13821 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13822 | TelephonyPermissions.enforceShellOnly( |
| 13823 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13824 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13825 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13826 | "setSatelliteControllerTimeoutDuration"); |
| 13827 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13828 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13829 | } |
| 13830 | |
| 13831 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13832 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13833 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13834 | * |
| 13835 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13836 | * of the following values to enable the override: |
| 13837 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13838 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13839 | * To disable the override, use -1 for handoverType. |
| 13840 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13841 | * delaySeconds after the emergency call starts. |
| 13842 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13843 | */ |
| 13844 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13845 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13846 | TelephonyPermissions.enforceShellOnly( |
| 13847 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13849 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13850 | "setEmergencyCallToSatelliteHandoverType"); |
| 13851 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13852 | handoverType, delaySeconds); |
| 13853 | } |
| 13854 | |
| 13855 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13856 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13857 | * |
| 13858 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13859 | * otherwise. |
| 13860 | * @param isProvisioned The overriding provision status. |
| 13861 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13862 | */ |
| 13863 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13864 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13865 | + ", isProvisioned=" + isProvisioned); |
| 13866 | TelephonyPermissions.enforceShellOnly( |
| 13867 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13868 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13869 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13870 | "setOemEnabledSatelliteProvisionStatus"); |
| 13871 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13872 | } |
| 13873 | |
| 13874 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13875 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13876 | * |
| 13877 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13878 | */ |
| 13879 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13880 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13881 | long locationCountryCodeTimestampNanos) { |
| 13882 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13883 | + String.join(", ", currentNetworkCountryCodes) |
| 13884 | + ", locationCountryCode=" + locationCountryCode |
| 13885 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13886 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13887 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13888 | TelephonyPermissions.enforceShellOnly( |
| 13889 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13891 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13892 | "setCachedLocationCountryCode"); |
| 13893 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13894 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13895 | locationCountryCodeTimestampNanos); |
| 13896 | } |
| 13897 | |
| 13898 | /** |
| 13899 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13900 | * access controller. |
| 13901 | * |
| 13902 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13903 | * otherwise. |
| 13904 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13905 | */ |
| 13906 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13907 | String s2CellFile, long locationFreshDurationNanos, |
| 13908 | List<String> satelliteCountryCodes) { |
| 13909 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13910 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13911 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13912 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13913 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13914 | TelephonyPermissions.enforceShellOnly( |
| 13915 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13916 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13917 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13918 | "setSatelliteAccessControlOverlayConfigs"); |
| 13919 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13920 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13921 | } |
| 13922 | |
| 13923 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13924 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13925 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13926 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13927 | * |
| 13928 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13929 | * satellite modem or not. |
| 13930 | * |
| 13931 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13932 | */ |
| 13933 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13934 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13935 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13936 | + "disabled"); |
| 13937 | return false; |
| 13938 | } |
| 13939 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13940 | TelephonyPermissions.enforceShellOnly( |
| 13941 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13943 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13944 | "setShouldSendDatagramToModemInDemoMode"); |
| 13945 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13946 | shouldSendToModemInDemoMode); |
| 13947 | } |
| 13948 | |
| 13949 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 13950 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 13951 | * |
| 13952 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 13953 | * the allowed state. |
| 13954 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 13955 | */ |
| 13956 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 13957 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13958 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 13959 | + "oemEnabledSatelliteFlag is disabled"); |
| 13960 | return false; |
| 13961 | } |
| 13962 | |
| 13963 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 13964 | + "state=" + state); |
| 13965 | TelephonyPermissions.enforceShellOnly( |
| 13966 | Binder.getCallingUid(), |
| 13967 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 13968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13969 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13970 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 13971 | return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache( |
| 13972 | state); |
| 13973 | } |
| 13974 | |
| 13975 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 13976 | * Sets the service defined in ComponentName to be bound. |
| 13977 | * |
| 13978 | * This should only be used for testing. |
| 13979 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 13980 | * {@code false} otherwise. |
| 13981 | */ |
| 13982 | @Override |
| 13983 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 13984 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 13985 | |
| 13986 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13987 | "setDomainSelectionServiceOverride"); |
| 13988 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13989 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 13990 | |
| 13991 | final long identity = Binder.clearCallingIdentity(); |
| 13992 | try { |
| 13993 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13994 | return DomainSelectionResolver.getInstance() |
| 13995 | .setDomainSelectionServiceOverride(componentName); |
| 13996 | } |
| 13997 | } finally { |
| 13998 | Binder.restoreCallingIdentity(identity); |
| 13999 | } |
| 14000 | return false; |
| 14001 | } |
| 14002 | |
| 14003 | /** |
| 14004 | * Clears the DomainSelectionService override. |
| 14005 | * |
| 14006 | * This should only be used for testing. |
| 14007 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14008 | * {@code false} otherwise. |
| 14009 | */ |
| 14010 | @Override |
| 14011 | public boolean clearDomainSelectionServiceOverride() { |
| 14012 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14013 | |
| 14014 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14015 | "clearDomainSelectionServiceOverride"); |
| 14016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14017 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14018 | |
| 14019 | final long identity = Binder.clearCallingIdentity(); |
| 14020 | try { |
| 14021 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14022 | return DomainSelectionResolver.getInstance() |
| 14023 | .clearDomainSelectionServiceOverride(); |
| 14024 | } |
| 14025 | } finally { |
| 14026 | Binder.restoreCallingIdentity(identity); |
| 14027 | } |
| 14028 | return false; |
| 14029 | } |
| 14030 | |
| 14031 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14032 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14033 | * |
| 14034 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14035 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14036 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14037 | * |
| 14038 | * @param enable if notifications about disclosure events should be enabled |
| 14039 | * @throws SecurityException if the caller does not have the required privileges |
| 14040 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14041 | */ |
| 14042 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14043 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14044 | enforceModifyPermission(); |
| 14045 | checkForIdentifierDisclosureNotificationSupport(); |
| 14046 | |
| 14047 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14048 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14049 | editor.apply(); |
| 14050 | |
| 14051 | // Each phone instance is responsible for updating its respective modem immediately |
| 14052 | // after we've made a preference change. |
| 14053 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14054 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14055 | } |
| 14056 | } |
| 14057 | |
| 14058 | /** |
| 14059 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14060 | * |
| 14061 | * @throws SecurityException if the caller does not have the required privileges |
| 14062 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14063 | */ |
| 14064 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14065 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14066 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14067 | checkForIdentifierDisclosureNotificationSupport(); |
| 14068 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14069 | } |
| 14070 | |
| 14071 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14072 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14073 | * are in use by the cellular modem. |
| 14074 | * |
| 14075 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14076 | * @throws SecurityException if the caller does not have the required privileges |
| 14077 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14078 | * and integrity algorithms in use |
| 14079 | * @hide |
| 14080 | */ |
| 14081 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14082 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14083 | enforceModifyPermission(); |
| 14084 | checkForNullCipherNotificationSupport(); |
| 14085 | |
| 14086 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14087 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14088 | editor.apply(); |
| 14089 | |
| 14090 | // Each phone instance is responsible for updating its respective modem immediately |
| 14091 | // after a preference change. |
| 14092 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14093 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14094 | } |
| 14095 | } |
| 14096 | |
| 14097 | /** |
| 14098 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14099 | * cellular modem. |
| 14100 | * |
| 14101 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14102 | * @throws SecurityException if the caller does not have the required privileges |
| 14103 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14104 | * and integrity algorithms in use |
| 14105 | * @hide |
| 14106 | */ |
| 14107 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14108 | public boolean isNullCipherNotificationsEnabled() { |
| 14109 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14110 | checkForNullCipherNotificationSupport(); |
| 14111 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14112 | } |
| 14113 | |
| 14114 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14115 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14116 | * |
| 14117 | * <p>This method behaves in one of the following ways: |
| 14118 | * <ul> |
| 14119 | * <li>return true : if the calling package has the appop permission {@link |
| 14120 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14121 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14122 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14123 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14124 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14125 | * </ul> |
| 14126 | */ |
| 14127 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14128 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14129 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14130 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14131 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14132 | return true; |
| 14133 | } |
| 14134 | } |
| 14135 | return false; |
| 14136 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14137 | |
| 14138 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14139 | * @return The subscription manager service instance. |
| 14140 | */ |
| 14141 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14142 | return SubscriptionManagerService.getInstance(); |
| 14143 | } |
| 14144 | |
| 14145 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14146 | * Class binds the consumer[callback] and carrierId. |
| 14147 | */ |
| 14148 | private static class CallerCallbackInfo { |
| 14149 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14150 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14151 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14152 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14153 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14154 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14155 | } |
| 14156 | |
| 14157 | public Consumer<Integer> getConsumer() { |
| 14158 | return mConsumer; |
| 14159 | } |
| 14160 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14161 | public Set<Integer> getCarrierIds() { |
| 14162 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14163 | } |
| 14164 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14165 | |
| 14166 | /* |
| 14167 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14168 | * But the context that is passed in is unused if the phone app is already alive. |
| 14169 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14170 | */ |
| 14171 | @VisibleForTesting |
| 14172 | public void setPackageManager(PackageManager packageManager) { |
| 14173 | mPackageManager = packageManager; |
| 14174 | } |
| 14175 | |
| 14176 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14177 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14178 | * But the context that is passed in is unused if the phone app is already alive. |
| 14179 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14180 | */ |
| 14181 | @VisibleForTesting |
| 14182 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14183 | mAppOps = appOps; |
| 14184 | } |
| 14185 | |
| 14186 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14187 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14188 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14189 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14190 | */ |
| 14191 | @VisibleForTesting |
| 14192 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14193 | mFeatureFlags = featureFlags; |
| 14194 | } |
| 14195 | |
| 14196 | /** |
| 14197 | * Make sure the device has required telephony feature |
| 14198 | * |
| 14199 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14200 | */ |
| 14201 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14202 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14203 | if (callingPackage == null || mPackageManager == null) { |
| 14204 | return; |
| 14205 | } |
| 14206 | |
| 14207 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14208 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14209 | Binder.getCallingUserHandle()) |
| 14210 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14211 | // Skip to check associated telephony feature, |
| 14212 | // if compatibility change is not enabled for the current process or |
| 14213 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14214 | return; |
| 14215 | } |
| 14216 | |
| 14217 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14218 | throw new UnsupportedOperationException( |
| 14219 | methodName + " is unsupported without " + telephonyFeature); |
| 14220 | } |
| 14221 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14222 | |
| 14223 | /** |
| 14224 | * Registers for the satellite communication allowed state changed. |
| 14225 | * |
| 14226 | * @param subId The subId of the subscription to register for the satellite communication |
| 14227 | * allowed state changed. |
| 14228 | * @param callback The callback to handle the satellite communication allowed |
| 14229 | * state changed event. |
| 14230 | * |
| 14231 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14232 | * |
| 14233 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14234 | */ |
| 14235 | @Override |
| 14236 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14237 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14238 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
| 14239 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14240 | subId, callback); |
| 14241 | } |
| 14242 | |
| 14243 | /** |
| 14244 | * Unregisters for the satellite communication allowed state changed. |
| 14245 | * If callback was not registered before, the request will be ignored. |
| 14246 | * |
| 14247 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14248 | * allowed state changed. |
| 14249 | * @param callback The callback that was passed to |
| 14250 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14251 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14252 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14253 | */ |
| 14254 | @Override |
| 14255 | public void unregisterForCommunicationAllowedStateChanged( |
| 14256 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14257 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
| 14258 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback); |
| 14259 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14260 | |
| 14261 | /** |
| 14262 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14263 | * |
| 14264 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14265 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14266 | * if the request is successful or an error code if the request failed. |
| 14267 | * |
| 14268 | * @throws SecurityException if the caller doesn't have required permission. |
| 14269 | */ |
| 14270 | @Override |
| 14271 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14272 | enforceModifyPermission(); |
| 14273 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
| 14274 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14275 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame^] | 14276 | |
| 14277 | /** |
| 14278 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14279 | * |
| 14280 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14281 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14282 | * |
| 14283 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14284 | */ |
| 14285 | @Override |
| 14286 | public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) { |
| 14287 | enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds"); |
| 14288 | mSatelliteController.requestProvisionSubscriberIds(result); |
| 14289 | } |
| 14290 | |
| 14291 | /** |
| 14292 | * Request to get provisioned status for given a satellite subscriber id. |
| 14293 | * |
| 14294 | * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check. |
| 14295 | * @param result The result receiver, which returns the provisioned status of the token if the |
| 14296 | * request is successful or an error code if the request failed. |
| 14297 | * |
| 14298 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14299 | */ |
| 14300 | @Override |
| 14301 | public void requestIsProvisioned(String satelliteSubscriberId, @NonNull ResultReceiver result) { |
| 14302 | enforceSatelliteCommunicationPermission("requestIsProvisioned"); |
| 14303 | mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result); |
| 14304 | } |
| 14305 | |
| 14306 | /** |
| 14307 | * Deliver the list of provisioned satellite subscriber ids. |
| 14308 | * |
| 14309 | * @param list List of provisioned satellite subscriber ids. |
| 14310 | * @param result The result receiver that returns whether deliver success or fail. |
| 14311 | * |
| 14312 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14313 | */ |
| 14314 | @Override |
| 14315 | public void provisionSatellite(List<ProvisionSubscriberId> list, |
| 14316 | @NonNull ResultReceiver result) { |
| 14317 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
| 14318 | mSatelliteController.provisionSatellite(list, result); |
| 14319 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14320 | } |