Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS; |
| 20 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 22 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 23 | import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 24 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 26 | import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; |
| 27 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED; |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 29 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 30 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 31 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 32 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 34 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 35 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 36 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 37 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 38 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 39 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 40 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 41 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 42 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 44 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 45 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 46 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 47 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 48 | import android.compat.annotation.ChangeId; |
| 49 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 50 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 51 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 52 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.content.Context; |
| 54 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 55 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 56 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 57 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.net.Uri; |
| 59 | import android.os.AsyncResult; |
| 60 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 61 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 62 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 63 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 65 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 66 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 67 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.os.Looper; |
| 69 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 71 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 72 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 74 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 75 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 76 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 77 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 78 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 80 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 81 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 82 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 83 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 84 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 85 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 86 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 87 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 88 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 89 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 90 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 91 | import android.telephony.AccessNetworkConstants; |
| 92 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 93 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 94 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 95 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 96 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 97 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 98 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 99 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 100 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 101 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 102 | import android.telephony.CellIdentityCdma; |
| 103 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 105 | import android.telephony.CellInfoGsm; |
| 106 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 107 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 108 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 110 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 111 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 112 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 113 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 114 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 115 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 116 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 117 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 118 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 119 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 121 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 122 | import android.telephony.SignalStrengthUpdateRequest; |
| 123 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 124 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 126 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 127 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 130 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 131 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 132 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 133 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 134 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 135 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 136 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 137 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 138 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 139 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 140 | import android.telephony.gba.GbaAuthRequest; |
| 141 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 142 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 143 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 145 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 146 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 147 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 154 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 155 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 156 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 158 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 160 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 163 | import android.telephony.satellite.NtnSignalStrength; |
| 164 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 165 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 166 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 167 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 170 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 171 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 172 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 174 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 175 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 176 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 177 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 178 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 179 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 194 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 206 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 211 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 212 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 214 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 218 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 219 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 221 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 222 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 225 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 227 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 228 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 229 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 230 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 231 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 232 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 233 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 234 | import com.android.internal.telephony.uicc.IccIoResult; |
| 235 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 236 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 238 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 239 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 243 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 244 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 245 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 246 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 247 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 248 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 249 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 250 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 251 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 252 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 253 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 254 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 255 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 256 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 257 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 258 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 259 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 260 | import com.android.services.telephony.TelecomAccountRegistry; |
| 261 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 262 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 263 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 264 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 265 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 266 | import java.io.IOException; |
| 267 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 268 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 270 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 271 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 272 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 273 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 274 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 275 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 276 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 277 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 278 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 279 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 280 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 281 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 282 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 283 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 284 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 285 | |
| 286 | /** |
| 287 | * Implementation of the ITelephony interface. |
| 288 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 289 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 291 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 292 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 293 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 294 | |
| 295 | // Message codes used with mMainThreadHandler |
| 296 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 297 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 298 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 299 | private static final int CMD_OPEN_CHANNEL = 9; |
| 300 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 301 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 302 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 303 | private static final int CMD_NV_READ_ITEM = 13; |
| 304 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 305 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 306 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 307 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 308 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 309 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 310 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 311 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 312 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 313 | private static final int CMD_SEND_ENVELOPE = 25; |
| 314 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 315 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 316 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 317 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 318 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 319 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 320 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 321 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 322 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 323 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 324 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 325 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 326 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 327 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 328 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 329 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 330 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 331 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 332 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 333 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 334 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 335 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 336 | private static final int CMD_SWITCH_SLOTS = 50; |
| 337 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 338 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 339 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 340 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 341 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 342 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 343 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 344 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 345 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 346 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 347 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 348 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 349 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 350 | private static final int CMD_MODEM_REBOOT = 64; |
| 351 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 352 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 353 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 354 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 355 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 356 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 357 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 358 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 359 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 360 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 361 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 362 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 363 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 364 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 365 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 366 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 367 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 368 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 369 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 370 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 371 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 372 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 373 | private static final int CMD_GET_CALL_WAITING = 87; |
| 374 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 375 | private static final int CMD_SET_CALL_WAITING = 89; |
| 376 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 377 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 378 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 379 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 380 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 381 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 382 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 383 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 384 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 385 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 386 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 387 | private static final int CMD_SET_SIM_POWER = 101; |
| 388 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 389 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 390 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 391 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 392 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 393 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 394 | 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] | 395 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 396 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 397 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 398 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 399 | private static final int CMD_ENABLE_VONR = 113; |
| 400 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 401 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 402 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 403 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 404 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 405 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 406 | // Parameters of select command. |
| 407 | private static final int SELECT_COMMAND = 0xA4; |
| 408 | private static final int SELECT_P1 = 0x04; |
| 409 | private static final int SELECT_P2 = 0; |
| 410 | private static final int SELECT_P3 = 0x10; |
| 411 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 412 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 413 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 414 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 415 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 416 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 417 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 418 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 419 | /** The singleton instance. */ |
| 420 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 421 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 423 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 424 | private FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 425 | private final CallManager mCM; |
| 426 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 427 | |
| 428 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 429 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 430 | private final UserManager mUserManager; |
| 431 | private final AppOpsManager mAppOps; |
| 432 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 433 | private final SharedPreferences mTelephonySharedPreferences; |
| 434 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 435 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 436 | private PackageManager mPackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 437 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 438 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 439 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 440 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 441 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 442 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 443 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 444 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 445 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 446 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 447 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 448 | // String to store multi SIM allowed |
| 449 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 450 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 451 | // The AID of ISD-R. |
| 452 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 453 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 454 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 455 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 456 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 457 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 458 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 459 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 460 | 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] | 461 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 462 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 463 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 464 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 465 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 466 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 467 | */ |
| 468 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 469 | "reset_network_erase_modem_config_enabled"; |
| 470 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 471 | 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] | 472 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 473 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 474 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 475 | /** |
| 476 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 477 | * one ICCID active at the same time. |
| 478 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 479 | * |
| 480 | * @hide |
| 481 | */ |
| 482 | @ChangeId |
| 483 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 484 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 485 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 486 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 487 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 488 | * operation fails. |
| 489 | */ |
| 490 | @ChangeId |
| 491 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 492 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 493 | |
| 494 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 495 | * A request object to use for transmitting data to an ICC. |
| 496 | */ |
| 497 | private static final class IccAPDUArgument { |
| 498 | public int channel, cla, command, p1, p2, p3; |
| 499 | public String data; |
| 500 | |
| 501 | public IccAPDUArgument(int channel, int cla, int command, |
| 502 | int p1, int p2, int p3, String data) { |
| 503 | this.channel = channel; |
| 504 | this.cla = cla; |
| 505 | this.command = command; |
| 506 | this.p1 = p1; |
| 507 | this.p2 = p2; |
| 508 | this.p3 = p3; |
| 509 | this.data = data; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 514 | * A request object to use for transmitting data to an ICC. |
| 515 | */ |
| 516 | private static final class ManualNetworkSelectionArgument { |
| 517 | public OperatorInfo operatorInfo; |
| 518 | public boolean persistSelection; |
| 519 | |
| 520 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 521 | this.operatorInfo = operatorInfo; |
| 522 | this.persistSelection = persistSelection; |
| 523 | } |
| 524 | } |
| 525 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 526 | private static final class PurchasePremiumCapabilityArgument { |
| 527 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 528 | public @NonNull IIntegerConsumer callback; |
| 529 | |
| 530 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 531 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 532 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 533 | this.callback = callback; |
| 534 | } |
| 535 | } |
| 536 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 537 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 539 | * request after sending. The main thread will notify the request when it is complete. |
| 540 | */ |
| 541 | private static final class MainThreadRequest { |
| 542 | /** The argument to use for the request */ |
| 543 | public Object argument; |
| 544 | /** The result of the request that is run on the main thread */ |
| 545 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 546 | // The subscriber id that this request applies to. Defaults to |
| 547 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 548 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 549 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 550 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 551 | public Phone phone; |
| 552 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 553 | public WorkSource workSource; |
| 554 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | public MainThreadRequest(Object argument) { |
| 556 | this.argument = argument; |
| 557 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 558 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 559 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 560 | this.argument = argument; |
| 561 | if (phone != null) { |
| 562 | this.phone = phone; |
| 563 | } |
| 564 | this.workSource = workSource; |
| 565 | } |
| 566 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 567 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 568 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 569 | if (subId != null) { |
| 570 | this.subId = subId; |
| 571 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 572 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 576 | private static final class IncomingThirdPartyCallArgs { |
| 577 | public final ComponentName component; |
| 578 | public final String callId; |
| 579 | public final String callerDisplayName; |
| 580 | |
| 581 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 582 | String callerDisplayName) { |
| 583 | this.component = component; |
| 584 | this.callId = callId; |
| 585 | this.callerDisplayName = callerDisplayName; |
| 586 | } |
| 587 | } |
| 588 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 589 | /** |
| 590 | * A handler that processes messages on the main thread in the phone process. Since many |
| 591 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 592 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 593 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 594 | * on, which will be notified when the operation completes and will contain the result of the |
| 595 | * request. |
| 596 | * |
| 597 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 598 | * note that request.result must be set to something non-null for the calling thread to |
| 599 | * unblock. |
| 600 | */ |
| 601 | private final class MainThreadHandler extends Handler { |
| 602 | @Override |
| 603 | public void handleMessage(Message msg) { |
| 604 | MainThreadRequest request; |
| 605 | Message onCompleted; |
| 606 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 607 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 608 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 609 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 610 | |
| 611 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 612 | case CMD_HANDLE_USSD_REQUEST: { |
| 613 | request = (MainThreadRequest) msg.obj; |
| 614 | final Phone phone = getPhoneFromRequest(request); |
| 615 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 616 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 618 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | if (!isUssdApiAllowed(request.subId)) { |
| 620 | // Carrier does not support use of this API, return failure. |
| 621 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 622 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 623 | Bundle returnData = new Bundle(); |
| 624 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 625 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
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 | request.result = true; |
| 628 | notifyRequester(request); |
| 629 | return; |
| 630 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 631 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | try { |
| 633 | request.result = phone != null |
| 634 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 635 | } catch (CallStateException cse) { |
| 636 | request.result = false; |
| 637 | } |
| 638 | // Wake up the requesting thread |
| 639 | notifyRequester(request); |
| 640 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 643 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 644 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 645 | final Phone phone = getPhoneFromRequest(request); |
| 646 | request.result = phone != null ? |
| 647 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 648 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 649 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 650 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 651 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 652 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 653 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 654 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 657 | uiccPort = getUiccPortFromRequest(request); |
| 658 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 659 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 660 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 661 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 662 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 663 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 664 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 665 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 666 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 667 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 668 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 669 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | break; |
| 671 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | ar = (AsyncResult) msg.obj; |
| 674 | request = (MainThreadRequest) ar.userObj; |
| 675 | if (ar.exception == null && ar.result != null) { |
| 676 | request.result = ar.result; |
| 677 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 678 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | if (ar.result == null) { |
| 680 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 683 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 684 | } else { |
| 685 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 686 | } |
| 687 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 688 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | break; |
| 690 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 692 | request = (MainThreadRequest) msg.obj; |
| 693 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 694 | uiccPort = getUiccPortFromRequest(request); |
| 695 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 696 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 697 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 698 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 699 | } else { |
| 700 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 701 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 702 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 703 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 704 | iccArgument.p2, |
| 705 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | } |
| 707 | break; |
| 708 | |
| 709 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 710 | ar = (AsyncResult) msg.obj; |
| 711 | request = (MainThreadRequest) ar.userObj; |
| 712 | if (ar.exception == null && ar.result != null) { |
| 713 | request.result = ar.result; |
| 714 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 715 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 716 | if (ar.result == null) { |
| 717 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 718 | } else if (ar.exception instanceof CommandException) { |
| 719 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 720 | ar.exception); |
| 721 | } else { |
| 722 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 723 | } |
| 724 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 725 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case CMD_EXCHANGE_SIM_IO: |
| 729 | request = (MainThreadRequest) msg.obj; |
| 730 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 731 | uiccPort = getUiccPortFromRequest(request); |
| 732 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 734 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 736 | } else { |
| 737 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 738 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 739 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 740 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 741 | iccArgument.data, onCompleted); |
| 742 | } |
| 743 | break; |
| 744 | |
| 745 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 746 | ar = (AsyncResult) msg.obj; |
| 747 | request = (MainThreadRequest) ar.userObj; |
| 748 | if (ar.exception == null && ar.result != null) { |
| 749 | request.result = ar.result; |
| 750 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 751 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 752 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 753 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 754 | break; |
| 755 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 756 | case CMD_SEND_ENVELOPE: |
| 757 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 758 | uiccPort = getUiccPortFromRequest(request); |
| 759 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 760 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 761 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 763 | } else { |
| 764 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 765 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 766 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 767 | break; |
| 768 | |
| 769 | case EVENT_SEND_ENVELOPE_DONE: |
| 770 | ar = (AsyncResult) msg.obj; |
| 771 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 772 | if (ar.exception == null && ar.result != null) { |
| 773 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 774 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 775 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 776 | if (ar.result == null) { |
| 777 | loge("sendEnvelopeWithStatus: Empty response"); |
| 778 | } else if (ar.exception instanceof CommandException) { |
| 779 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 780 | ar.exception); |
| 781 | } else { |
| 782 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 783 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 784 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 785 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 786 | break; |
| 787 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 788 | case CMD_OPEN_CHANNEL: |
| 789 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 790 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 791 | IccLogicalChannelRequest openChannelRequest = |
| 792 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 793 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 794 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 795 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 796 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 797 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 798 | } else { |
| 799 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 800 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 801 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 802 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | case EVENT_OPEN_CHANNEL_DONE: |
| 806 | ar = (AsyncResult) msg.obj; |
| 807 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 808 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 809 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 810 | int[] result = (int[]) ar.result; |
| 811 | int channelId = result[0]; |
| 812 | byte[] selectResponse = null; |
| 813 | if (result.length > 1) { |
| 814 | selectResponse = new byte[result.length - 1]; |
| 815 | for (int i = 1; i < result.length; ++i) { |
| 816 | selectResponse[i - 1] = (byte) result[i]; |
| 817 | } |
| 818 | } |
| 819 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 820 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 821 | |
| 822 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 823 | if (uiccPort == null) { |
| 824 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 825 | } else { |
| 826 | IccLogicalChannelRequest channelRequest = |
| 827 | (IccLogicalChannelRequest) request.argument; |
| 828 | channelRequest.channel = channelId; |
| 829 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 830 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 831 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 832 | if (ar.result == null) { |
| 833 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 834 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 835 | if (ar.exception != null) { |
| 836 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 837 | } |
| 838 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 839 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 840 | if (ar.exception instanceof CommandException) { |
| 841 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 842 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 843 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 844 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 845 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 846 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 850 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 851 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 852 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 853 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 854 | break; |
| 855 | |
| 856 | case CMD_CLOSE_CHANNEL: |
| 857 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 858 | uiccPort = getUiccPortFromRequest(request); |
| 859 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 860 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 861 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 862 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 863 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 864 | } else { |
| 865 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 866 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 867 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 871 | ar = (AsyncResult) msg.obj; |
| 872 | request = (MainThreadRequest) ar.userObj; |
| 873 | if (ar.exception == null) { |
| 874 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 875 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 876 | if (uiccPort == null) { |
| 877 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 878 | } else { |
| 879 | final int channelId = (Integer) request.argument; |
| 880 | uiccPort.onLogicalChannelClosed(channelId); |
| 881 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 882 | } else { |
| 883 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 884 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 885 | if (ar.exception instanceof CommandException) { |
| 886 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 887 | CommandException.Error error = |
| 888 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 889 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 890 | // should only throw exceptions from the binder threads. |
| 891 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 892 | "iccCloseLogicalChannel: invalid argument "); |
| 893 | } |
| 894 | } else { |
| 895 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 896 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 897 | request.result = (exception != null) ? exception : |
| 898 | new IllegalStateException( |
| 899 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 900 | } |
| 901 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 902 | break; |
| 903 | |
| 904 | case CMD_NV_READ_ITEM: |
| 905 | request = (MainThreadRequest) msg.obj; |
| 906 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 907 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 908 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 909 | break; |
| 910 | |
| 911 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 912 | ar = (AsyncResult) msg.obj; |
| 913 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 914 | if (ar.exception == null && ar.result != null) { |
| 915 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 916 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 917 | request.result = ""; |
| 918 | if (ar.result == null) { |
| 919 | loge("nvReadItem: Empty response"); |
| 920 | } else if (ar.exception instanceof CommandException) { |
| 921 | loge("nvReadItem: CommandException: " + |
| 922 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 923 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 924 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 925 | } |
| 926 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 927 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 928 | break; |
| 929 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 930 | case CMD_NV_WRITE_ITEM: |
| 931 | request = (MainThreadRequest) msg.obj; |
| 932 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 933 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 934 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 935 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 936 | break; |
| 937 | |
| 938 | case EVENT_NV_WRITE_ITEM_DONE: |
| 939 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 940 | break; |
| 941 | |
| 942 | case CMD_NV_WRITE_CDMA_PRL: |
| 943 | request = (MainThreadRequest) msg.obj; |
| 944 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 945 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 946 | break; |
| 947 | |
| 948 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 949 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 950 | break; |
| 951 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 952 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 953 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 954 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 955 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 956 | break; |
| 957 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 958 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 959 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 960 | break; |
| 961 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 962 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 963 | request = (MainThreadRequest) msg.obj; |
| 964 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 965 | request); |
| 966 | Phone phone = getPhoneFromRequest(request); |
| 967 | if (phone != null) { |
| 968 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 969 | } else { |
| 970 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 971 | request.result = false; |
| 972 | notifyRequester(request); |
| 973 | } |
| 974 | break; |
| 975 | } |
| 976 | |
| 977 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 978 | ar = (AsyncResult) msg.obj; |
| 979 | request = (MainThreadRequest) ar.userObj; |
| 980 | if (ar.exception == null && ar.result != null) { |
| 981 | request.result = ar.result; |
| 982 | } else { |
| 983 | // request.result must be set to something non-null |
| 984 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 985 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 986 | request.result = ar.result; |
| 987 | } else { |
| 988 | request.result = false; |
| 989 | } |
| 990 | if (ar.result == null) { |
| 991 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 992 | } else if (ar.exception instanceof CommandException) { |
| 993 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 994 | + ar.exception); |
| 995 | } else { |
| 996 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 997 | } |
| 998 | } |
| 999 | notifyRequester(request); |
| 1000 | break; |
| 1001 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1002 | case CMD_IS_VONR_ENABLED: { |
| 1003 | request = (MainThreadRequest) msg.obj; |
| 1004 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1005 | request); |
| 1006 | Phone phone = getPhoneFromRequest(request); |
| 1007 | if (phone != null) { |
| 1008 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1009 | } else { |
| 1010 | loge("isVoNrEnabled: No phone object"); |
| 1011 | request.result = false; |
| 1012 | notifyRequester(request); |
| 1013 | } |
| 1014 | break; |
| 1015 | } |
| 1016 | |
| 1017 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1018 | ar = (AsyncResult) msg.obj; |
| 1019 | request = (MainThreadRequest) ar.userObj; |
| 1020 | if (ar.exception == null && ar.result != null) { |
| 1021 | request.result = ar.result; |
| 1022 | } else { |
| 1023 | // request.result must be set to something non-null |
| 1024 | // for the calling thread to unblock |
| 1025 | if (ar.result != null) { |
| 1026 | request.result = ar.result; |
| 1027 | } else { |
| 1028 | request.result = false; |
| 1029 | } |
| 1030 | if (ar.result == null) { |
| 1031 | loge("isVoNrEnabled: Empty response"); |
| 1032 | } else if (ar.exception instanceof CommandException) { |
| 1033 | loge("isVoNrEnabled: CommandException: " |
| 1034 | + ar.exception); |
| 1035 | } else { |
| 1036 | loge("isVoNrEnabled: Unknown exception"); |
| 1037 | } |
| 1038 | } |
| 1039 | notifyRequester(request); |
| 1040 | break; |
| 1041 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1042 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1043 | request = (MainThreadRequest) msg.obj; |
| 1044 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1045 | Phone phone = getPhoneFromRequest(request); |
| 1046 | if (phone != null) { |
| 1047 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1048 | request.workSource); |
| 1049 | } else { |
| 1050 | loge("enableNrDualConnectivity: No phone object"); |
| 1051 | request.result = |
| 1052 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1053 | notifyRequester(request); |
| 1054 | } |
| 1055 | break; |
| 1056 | } |
| 1057 | |
| 1058 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1059 | ar = (AsyncResult) msg.obj; |
| 1060 | request = (MainThreadRequest) ar.userObj; |
| 1061 | if (ar.exception == null) { |
| 1062 | request.result = |
| 1063 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1064 | } else { |
| 1065 | request.result = |
| 1066 | TelephonyManager |
| 1067 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1068 | if (ar.exception instanceof CommandException) { |
| 1069 | CommandException.Error error = |
| 1070 | ((CommandException) (ar.exception)).getCommandError(); |
| 1071 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1072 | request.result = |
| 1073 | TelephonyManager |
| 1074 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1075 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1076 | request.result = |
| 1077 | TelephonyManager |
| 1078 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1079 | } |
| 1080 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1081 | + ar.exception); |
| 1082 | } else { |
| 1083 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1084 | } |
| 1085 | } |
| 1086 | notifyRequester(request); |
| 1087 | break; |
| 1088 | } |
| 1089 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1090 | case CMD_ENABLE_VONR: { |
| 1091 | request = (MainThreadRequest) msg.obj; |
| 1092 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1093 | Phone phone = getPhoneFromRequest(request); |
| 1094 | if (phone != null) { |
| 1095 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1096 | request.workSource); |
| 1097 | } else { |
| 1098 | loge("setVoNrEnabled: No phone object"); |
| 1099 | request.result = |
| 1100 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1101 | notifyRequester(request); |
| 1102 | } |
| 1103 | break; |
| 1104 | } |
| 1105 | |
| 1106 | case EVENT_ENABLE_VONR_DONE: { |
| 1107 | ar = (AsyncResult) msg.obj; |
| 1108 | request = (MainThreadRequest) ar.userObj; |
| 1109 | if (ar.exception == null) { |
| 1110 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1111 | } else { |
| 1112 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1113 | if (ar.exception instanceof CommandException) { |
| 1114 | CommandException.Error error = |
| 1115 | ((CommandException) (ar.exception)).getCommandError(); |
| 1116 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1117 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1118 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1119 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1120 | } else { |
| 1121 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1122 | } |
| 1123 | loge("setVoNrEnabled" + ": CommandException: " |
| 1124 | + ar.exception); |
| 1125 | } else { |
| 1126 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1127 | } |
| 1128 | } |
| 1129 | notifyRequester(request); |
| 1130 | break; |
| 1131 | } |
| 1132 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1133 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1134 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1135 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1136 | request); |
| 1137 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1138 | break; |
| 1139 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1140 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
| 1143 | if (ar.exception == null && ar.result != null) { |
| 1144 | request.result = ar.result; // Integer |
| 1145 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1146 | // request.result must be set to something non-null |
| 1147 | // for the calling thread to unblock |
| 1148 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1149 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1150 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1151 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1152 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1153 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1154 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1155 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1156 | } |
| 1157 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1158 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1159 | break; |
| 1160 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1161 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1162 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1163 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1164 | request); |
| 1165 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1166 | (Pair<Integer, Long>) request.argument; |
| 1167 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1168 | reasonWithNetworkTypes.first, |
| 1169 | reasonWithNetworkTypes.second, |
| 1170 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1171 | break; |
| 1172 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1173 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1174 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1175 | break; |
| 1176 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1177 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1178 | request = (MainThreadRequest) msg.obj; |
| 1179 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1180 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1181 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1182 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1183 | break; |
| 1184 | |
| 1185 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1186 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1187 | break; |
| 1188 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1189 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1190 | request = (MainThreadRequest) msg.obj; |
| 1191 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1192 | request); |
| 1193 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1194 | break; |
| 1195 | |
| 1196 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1197 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1198 | break; |
| 1199 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1200 | case CMD_PERFORM_NETWORK_SCAN: |
| 1201 | request = (MainThreadRequest) msg.obj; |
| 1202 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1203 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1204 | break; |
| 1205 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | request = (MainThreadRequest) msg.obj; |
| 1208 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1210 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1211 | request.argument; |
| 1212 | int callForwardingReason = args.first; |
| 1213 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1215 | } |
| 1216 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | ar = (AsyncResult) msg.obj; |
| 1218 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1220 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1221 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1222 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1225 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1226 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1227 | // any service for voice call. |
| 1228 | if ((callForwardInfo.serviceClass |
| 1229 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1230 | callForwardingInfo = new CallForwardingInfo( |
| 1231 | callForwardInfo.status |
| 1232 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | callForwardInfo.reason, |
| 1234 | callForwardInfo.number, |
| 1235 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1236 | break; |
| 1237 | } |
| 1238 | } |
| 1239 | // Didn't find a call forward info for voice call. |
| 1240 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1242 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1244 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | } else { |
| 1246 | if (ar.result == null) { |
| 1247 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1248 | } |
| 1249 | if (ar.exception != null) { |
| 1250 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1251 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1252 | int errorCode = TelephonyManager |
| 1253 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | if (ar.exception instanceof CommandException) { |
| 1255 | CommandException.Error error = |
| 1256 | ((CommandException) (ar.exception)).getCommandError(); |
| 1257 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1258 | errorCode = TelephonyManager |
| 1259 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1261 | errorCode = TelephonyManager |
| 1262 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | } |
| 1264 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1269 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | request = (MainThreadRequest) msg.obj; |
| 1272 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1273 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1276 | request.argument).first; |
| 1277 | request.phone.setCallForwardingOption( |
| 1278 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1279 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | callForwardingInfoToSet.getReason(), |
| 1282 | callForwardingInfoToSet.getNumber(), |
| 1283 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1284 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1286 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | ar = (AsyncResult) msg.obj; |
| 1289 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1290 | Consumer<Integer> callback = |
| 1291 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1292 | request.argument).second; |
| 1293 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1295 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1296 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1297 | if (ar.exception instanceof CommandException) { |
| 1298 | CommandException.Error error = |
| 1299 | ((CommandException) (ar.exception)).getCommandError(); |
| 1300 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1301 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1302 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1304 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1305 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | callback.accept(errorCode); |
| 1309 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1310 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1314 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | request = (MainThreadRequest) msg.obj; |
| 1317 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1318 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1319 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1320 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | ar = (AsyncResult) msg.obj; |
| 1324 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1326 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1327 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1328 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | // Service Class is a bit mask per 3gpp 27.007. |
| 1330 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1331 | if (callForwardResults.length > 1 |
| 1332 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1333 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1334 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1335 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1336 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1338 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1339 | } |
| 1340 | } else { |
| 1341 | if (ar.result == null) { |
| 1342 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1343 | } |
| 1344 | if (ar.exception != null) { |
| 1345 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1346 | } |
| 1347 | if (ar.exception instanceof CommandException) { |
| 1348 | CommandException.Error error = |
| 1349 | ((CommandException) (ar.exception)).getCommandError(); |
| 1350 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1351 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1353 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1354 | callWaitingStatus = |
| 1355 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1359 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1361 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1363 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | request = (MainThreadRequest) msg.obj; |
| 1365 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1366 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1367 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
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 EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | ar = (AsyncResult) msg.obj; |
| 1373 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1374 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1375 | Consumer<Integer> callback = |
| 1376 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1377 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1378 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1379 | if (ar.exception instanceof CommandException) { |
| 1380 | CommandException.Error error = |
| 1381 | ((CommandException) (ar.exception)).getCommandError(); |
| 1382 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1383 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1384 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1385 | callback.accept( |
| 1386 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1387 | } else { |
| 1388 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1389 | } |
| 1390 | } else { |
| 1391 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1392 | } |
| 1393 | } else { |
| 1394 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1395 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1396 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1397 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1398 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1399 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1400 | ar = (AsyncResult) msg.obj; |
| 1401 | request = (MainThreadRequest) ar.userObj; |
| 1402 | CellNetworkScanResult cellScanResult; |
| 1403 | if (ar.exception == null && ar.result != null) { |
| 1404 | cellScanResult = new CellNetworkScanResult( |
| 1405 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1406 | (List<OperatorInfo>) ar.result); |
| 1407 | } else { |
| 1408 | if (ar.result == null) { |
| 1409 | loge("getCellNetworkScanResults: Empty response"); |
| 1410 | } |
| 1411 | if (ar.exception != null) { |
| 1412 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1413 | } |
| 1414 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1415 | if (ar.exception instanceof CommandException) { |
| 1416 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1417 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1418 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1419 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1420 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1421 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1422 | } |
| 1423 | } |
| 1424 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1425 | } |
| 1426 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1427 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1428 | break; |
| 1429 | |
| 1430 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1431 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1432 | ManualNetworkSelectionArgument selArg = |
| 1433 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1434 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1435 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1436 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1437 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | |
| 1440 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1441 | ar = (AsyncResult) msg.obj; |
| 1442 | request = (MainThreadRequest) ar.userObj; |
| 1443 | if (ar.exception == null) { |
| 1444 | request.result = true; |
| 1445 | } else { |
| 1446 | request.result = false; |
| 1447 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1448 | } |
| 1449 | notifyRequester(request); |
| 1450 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1451 | break; |
| 1452 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1453 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1454 | request = (MainThreadRequest) msg.obj; |
| 1455 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1456 | if (defaultPhone != null) { |
| 1457 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1458 | } else { |
| 1459 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1460 | Bundle bundle = new Bundle(); |
| 1461 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1462 | new ModemActivityInfo(0, 0, 0, |
| 1463 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1464 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1465 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1466 | break; |
| 1467 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1468 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1469 | ar = (AsyncResult) msg.obj; |
| 1470 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1471 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1472 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1473 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1474 | if (mLastModemActivityInfo == null) { |
| 1475 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1476 | mLastModemActivitySpecificInfo[0] = |
| 1477 | new ActivityStatsTechSpecificInfo( |
| 1478 | 0, |
| 1479 | 0, |
| 1480 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1481 | 0); |
| 1482 | mLastModemActivityInfo = |
| 1483 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1484 | } |
| 1485 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1486 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1487 | // Update the last modem activity info and the result of the request. |
| 1488 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1489 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1490 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1491 | } else { |
| 1492 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1493 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1494 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1495 | // We don't want to return mLastModemActivityInfo which is updated |
| 1496 | // inside mergeModemActivityInfo() |
| 1497 | ret = new ModemActivityInfo( |
| 1498 | mLastModemActivityInfo.getTimestampMillis(), |
| 1499 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1500 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1501 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1502 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1503 | } else { |
| 1504 | if (ar.result == null) { |
| 1505 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1506 | error = TelephonyManager.ModemActivityInfoException |
| 1507 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1508 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1509 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1510 | error = TelephonyManager.ModemActivityInfoException |
| 1511 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1512 | } else { |
| 1513 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1514 | error = TelephonyManager.ModemActivityInfoException |
| 1515 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1516 | } |
| 1517 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1518 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1519 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1520 | bundle.putParcelable( |
| 1521 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1522 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1523 | } else { |
| 1524 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1525 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1526 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1527 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1528 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1529 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1530 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1531 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1532 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1533 | CarrierRestrictionRules argument = |
| 1534 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1535 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1536 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1537 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1538 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1539 | |
| 1540 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1541 | ar = (AsyncResult) msg.obj; |
| 1542 | request = (MainThreadRequest) ar.userObj; |
| 1543 | if (ar.exception == null && ar.result != null) { |
| 1544 | request.result = ar.result; |
| 1545 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1546 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1547 | if (ar.exception instanceof CommandException) { |
| 1548 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1549 | CommandException.Error error = |
| 1550 | ((CommandException) (ar.exception)).getCommandError(); |
| 1551 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1552 | request.result = |
| 1553 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1554 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1555 | } else { |
| 1556 | loge("setAllowedCarriers: Unknown exception"); |
| 1557 | } |
| 1558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1559 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1560 | break; |
| 1561 | |
| 1562 | case CMD_GET_ALLOWED_CARRIERS: |
| 1563 | request = (MainThreadRequest) msg.obj; |
| 1564 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1565 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1566 | break; |
| 1567 | |
| 1568 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1569 | ar = (AsyncResult) msg.obj; |
| 1570 | request = (MainThreadRequest) ar.userObj; |
| 1571 | if (ar.exception == null && ar.result != null) { |
| 1572 | request.result = ar.result; |
| 1573 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1574 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1575 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1576 | if (ar.result == null) { |
| 1577 | loge("getAllowedCarriers: Empty response"); |
| 1578 | } else if (ar.exception instanceof CommandException) { |
| 1579 | loge("getAllowedCarriers: CommandException: " + |
| 1580 | ar.exception); |
| 1581 | } else { |
| 1582 | loge("getAllowedCarriers: Unknown exception"); |
| 1583 | } |
| 1584 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1585 | if (request.argument != null) { |
| 1586 | // This is for the implementation of carrierRestrictionStatus. |
| 1587 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1588 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1589 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1590 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1591 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1592 | CarrierRestrictionRules carrierRestrictionRules = |
| 1593 | (CarrierRestrictionRules) ar.result; |
| 1594 | int carrierId = -1; |
| 1595 | try { |
| 1596 | CarrierIdentifier carrierIdentifier = |
| 1597 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1598 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1599 | carrierIdentifier); |
| 1600 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1601 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1602 | } |
| 1603 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1604 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1605 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1606 | lockStatus = TelephonyManager |
| 1607 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1608 | } |
| 1609 | } else { |
| 1610 | Rlog.e(LOG_TAG, |
| 1611 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1612 | } |
| 1613 | callback.accept(lockStatus); |
| 1614 | } else { |
| 1615 | // This is for the implementation of getAllowedCarriers. |
| 1616 | notifyRequester(request); |
| 1617 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1618 | break; |
| 1619 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1620 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1621 | ar = (AsyncResult) msg.obj; |
| 1622 | request = (MainThreadRequest) ar.userObj; |
| 1623 | if (ar.exception == null && ar.result != null) { |
| 1624 | request.result = ar.result; |
| 1625 | } else { |
| 1626 | request.result = new IllegalArgumentException( |
| 1627 | "Failed to retrieve Forbidden Plmns"); |
| 1628 | if (ar.result == null) { |
| 1629 | loge("getForbiddenPlmns: Empty response"); |
| 1630 | } else { |
| 1631 | loge("getForbiddenPlmns: Unknown exception"); |
| 1632 | } |
| 1633 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1634 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1635 | break; |
| 1636 | |
| 1637 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1638 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1639 | uiccPort = getUiccPortFromRequest(request); |
| 1640 | if (uiccPort == null) { |
| 1641 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1642 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1643 | "getForbiddenPlmns() UiccPort is null"); |
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 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1648 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1649 | if (uiccApp == null) { |
| 1650 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1651 | + appType); |
| 1652 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1653 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1654 | break; |
| 1655 | } else { |
| 1656 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1657 | + " specified type -- " + appType); |
| 1658 | } |
| 1659 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1660 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1661 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1662 | break; |
| 1663 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1664 | case CMD_SWITCH_SLOTS: |
| 1665 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1666 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1667 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1668 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1669 | break; |
| 1670 | |
| 1671 | case EVENT_SWITCH_SLOTS_DONE: |
| 1672 | ar = (AsyncResult) msg.obj; |
| 1673 | request = (MainThreadRequest) ar.userObj; |
| 1674 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1675 | notifyRequester(request); |
| 1676 | break; |
| 1677 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1678 | request = (MainThreadRequest) msg.obj; |
| 1679 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1680 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1681 | break; |
| 1682 | |
| 1683 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1684 | ar = (AsyncResult) msg.obj; |
| 1685 | request = (MainThreadRequest) ar.userObj; |
| 1686 | if (ar.exception != null) { |
| 1687 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1688 | } else { |
| 1689 | int mode = ((int[]) ar.result)[0]; |
| 1690 | if (mode == 0) { |
| 1691 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1692 | } else { |
| 1693 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1694 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1695 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1696 | notifyRequester(request); |
| 1697 | break; |
| 1698 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1699 | request = (MainThreadRequest) msg.obj; |
| 1700 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1701 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1702 | break; |
| 1703 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1704 | ar = (AsyncResult) msg.obj; |
| 1705 | request = (MainThreadRequest) ar.userObj; |
| 1706 | if (ar.exception != null) { |
| 1707 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1708 | } else { |
| 1709 | request.result = ((int[]) ar.result)[0]; |
| 1710 | } |
| 1711 | notifyRequester(request); |
| 1712 | break; |
| 1713 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1714 | request = (MainThreadRequest) msg.obj; |
| 1715 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1716 | int mode = (int) request.argument; |
| 1717 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1718 | break; |
| 1719 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1720 | ar = (AsyncResult) msg.obj; |
| 1721 | request = (MainThreadRequest) ar.userObj; |
| 1722 | request.result = ar.exception == null; |
| 1723 | notifyRequester(request); |
| 1724 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1725 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1726 | request = (MainThreadRequest) msg.obj; |
| 1727 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1728 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1729 | break; |
| 1730 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1731 | ar = (AsyncResult) msg.obj; |
| 1732 | request = (MainThreadRequest) ar.userObj; |
| 1733 | if (ar.exception != null) { |
| 1734 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1735 | } else { |
| 1736 | request.result = ((int[]) ar.result)[0]; |
| 1737 | } |
| 1738 | notifyRequester(request); |
| 1739 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1740 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1741 | request = (MainThreadRequest) msg.obj; |
| 1742 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1743 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1744 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1745 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1746 | break; |
| 1747 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1748 | ar = (AsyncResult) msg.obj; |
| 1749 | request = (MainThreadRequest) ar.userObj; |
| 1750 | request.result = ar.exception == null; |
| 1751 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1752 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1753 | case CMD_GET_ALL_CELL_INFO: |
| 1754 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1755 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1756 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1757 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1758 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1759 | ar = (AsyncResult) msg.obj; |
| 1760 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1761 | // If a timeout occurs, the response will be null |
| 1762 | request.result = (ar.exception == null && ar.result != null) |
| 1763 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1764 | synchronized (request) { |
| 1765 | request.notifyAll(); |
| 1766 | } |
| 1767 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1768 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1769 | request = (MainThreadRequest) msg.obj; |
| 1770 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1771 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1772 | break; |
| 1773 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1774 | ar = (AsyncResult) msg.obj; |
| 1775 | request = (MainThreadRequest) ar.userObj; |
| 1776 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1777 | try { |
| 1778 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1779 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1780 | cb.onError( |
| 1781 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1782 | ar.exception.getClass().getName(), |
| 1783 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1784 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1785 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1786 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1787 | } else { |
| 1788 | // use the result as returned |
| 1789 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1790 | } |
| 1791 | } catch (RemoteException re) { |
| 1792 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1793 | } |
| 1794 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1795 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1796 | request = (MainThreadRequest) msg.obj; |
| 1797 | WorkSource ws = (WorkSource) request.argument; |
| 1798 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1799 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1800 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1801 | } |
| 1802 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1803 | ar = (AsyncResult) msg.obj; |
| 1804 | request = (MainThreadRequest) ar.userObj; |
| 1805 | if (ar.exception == null) { |
| 1806 | request.result = ar.result; |
| 1807 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1808 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1809 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1810 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | synchronized (request) { |
| 1814 | request.notifyAll(); |
| 1815 | } |
| 1816 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1817 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1818 | case CMD_MODEM_REBOOT: |
| 1819 | request = (MainThreadRequest) msg.obj; |
| 1820 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1821 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1822 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1823 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1824 | handleNullReturnEvent(msg, "rebootModem"); |
| 1825 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1826 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1827 | request = (MainThreadRequest) msg.obj; |
| 1828 | boolean enable = (boolean) request.argument; |
| 1829 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1830 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1831 | PhoneConfigurationManager.getInstance() |
| 1832 | .enablePhone(request.phone, enable, onCompleted); |
| 1833 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1834 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1835 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1836 | ar = (AsyncResult) msg.obj; |
| 1837 | request = (MainThreadRequest) ar.userObj; |
| 1838 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1839 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1840 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1841 | if ((boolean) request.result) { |
| 1842 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1843 | updateModemStateMetrics(); |
| 1844 | } else { |
| 1845 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1846 | + ar.exception); |
| 1847 | } |
| 1848 | notifyRequester(request); |
| 1849 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1850 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1851 | case CMD_GET_MODEM_STATUS: |
| 1852 | request = (MainThreadRequest) msg.obj; |
| 1853 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1854 | PhoneConfigurationManager.getInstance() |
| 1855 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1856 | break; |
| 1857 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1858 | ar = (AsyncResult) msg.obj; |
| 1859 | request = (MainThreadRequest) ar.userObj; |
| 1860 | int id = request.phone.getPhoneId(); |
| 1861 | if (ar.exception == null && ar.result != null) { |
| 1862 | request.result = ar.result; |
| 1863 | //update the cache as modem status has changed |
| 1864 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1865 | (boolean) request.result); |
| 1866 | } else { |
| 1867 | // Return true if modem status cannot be retrieved. For most cases, |
| 1868 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1869 | // and disable modem are not supported. Modem is always on. |
| 1870 | // TODO: this should be fixed in R to support a third |
| 1871 | // status UNKNOWN b/131631629 |
| 1872 | request.result = true; |
| 1873 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1874 | + ar.exception); |
| 1875 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1876 | notifyRequester(request); |
| 1877 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1878 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1879 | request = (MainThreadRequest) msg.obj; |
| 1880 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1881 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1882 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1883 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1884 | break; |
| 1885 | } |
| 1886 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1887 | ar = (AsyncResult) msg.obj; |
| 1888 | request = (MainThreadRequest) ar.userObj; |
| 1889 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1890 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1891 | args.second.accept(ar.exception == null); |
| 1892 | notifyRequester(request); |
| 1893 | break; |
| 1894 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1895 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1896 | request = (MainThreadRequest) msg.obj; |
| 1897 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1898 | Phone phone = getPhoneFromRequest(request); |
| 1899 | if (phone != null) { |
| 1900 | phone.getSystemSelectionChannels(onCompleted); |
| 1901 | } else { |
| 1902 | loge("getSystemSelectionChannels: No phone object"); |
| 1903 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1904 | notifyRequester(request); |
| 1905 | } |
| 1906 | break; |
| 1907 | } |
| 1908 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1909 | ar = (AsyncResult) msg.obj; |
| 1910 | request = (MainThreadRequest) ar.userObj; |
| 1911 | if (ar.exception == null && ar.result != null) { |
| 1912 | request.result = ar.result; |
| 1913 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1914 | request.result = new IllegalStateException( |
| 1915 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1916 | if (ar.result == null) { |
| 1917 | loge("getSystemSelectionChannels: Empty response"); |
| 1918 | } else { |
| 1919 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1920 | } |
| 1921 | } |
| 1922 | notifyRequester(request); |
| 1923 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1924 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1925 | ar = (AsyncResult) msg.obj; |
| 1926 | request = (MainThreadRequest) ar.userObj; |
| 1927 | if (ar.exception == null && ar.result != null) { |
| 1928 | request.result = ar.result; |
| 1929 | } else { |
| 1930 | request.result = -1; |
| 1931 | loge("Failed to set Forbidden Plmns"); |
| 1932 | if (ar.result == null) { |
| 1933 | loge("setForbidenPlmns: Empty response"); |
| 1934 | } else if (ar.exception != null) { |
| 1935 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1936 | request.result = -1; |
| 1937 | } else { |
| 1938 | loge("setForbiddenPlmns: Unknown exception"); |
| 1939 | } |
| 1940 | } |
| 1941 | notifyRequester(request); |
| 1942 | break; |
| 1943 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1944 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1945 | uiccPort = getUiccPortFromRequest(request); |
| 1946 | if (uiccPort == null) { |
| 1947 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1948 | request.result = -1; |
| 1949 | notifyRequester(request); |
| 1950 | break; |
| 1951 | } |
| 1952 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1953 | (Pair<Integer, List<String>>) request.argument; |
| 1954 | appType = setFplmnsArgs.first; |
| 1955 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1956 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1957 | if (uiccApp == null) { |
| 1958 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1959 | request.result = -1; |
| 1960 | loge("Failed to get UICC App"); |
| 1961 | notifyRequester(request); |
| 1962 | } else { |
| 1963 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1964 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1965 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1966 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1967 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1968 | case CMD_ERASE_MODEM_CONFIG: |
| 1969 | request = (MainThreadRequest) msg.obj; |
| 1970 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1971 | defaultPhone.eraseModemConfig(onCompleted); |
| 1972 | break; |
| 1973 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1974 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1975 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1976 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1977 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1978 | request = (MainThreadRequest) msg.obj; |
| 1979 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1980 | notifyRequester(request); |
| 1981 | break; |
| 1982 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1983 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1984 | request = (MainThreadRequest) msg.obj; |
| 1985 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1986 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1987 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1988 | changed.first, changed.second, onCompleted); |
| 1989 | break; |
| 1990 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1991 | ar = (AsyncResult) msg.obj; |
| 1992 | request = (MainThreadRequest) ar.userObj; |
| 1993 | if (ar.exception == null) { |
| 1994 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1995 | // If the operation is successful, update the PIN storage |
| 1996 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1997 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1998 | UiccController.getInstance().getPinStorage() |
| 1999 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2000 | } else { |
| 2001 | request.result = msg.arg1; |
| 2002 | } |
| 2003 | notifyRequester(request); |
| 2004 | break; |
| 2005 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2006 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2007 | request = (MainThreadRequest) msg.obj; |
| 2008 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2009 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2010 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2011 | enabled.first, enabled.second, onCompleted); |
| 2012 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2013 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2014 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2015 | ar = (AsyncResult) msg.obj; |
| 2016 | request = (MainThreadRequest) ar.userObj; |
| 2017 | if (ar.exception == null) { |
| 2018 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2019 | // If the operation is successful, update the PIN storage |
| 2020 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2021 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2022 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2023 | UiccController.getInstance().getPinStorage() |
| 2024 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2025 | } else { |
| 2026 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2027 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2028 | } else { |
| 2029 | request.result = msg.arg1; |
| 2030 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2031 | |
| 2032 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2033 | notifyRequester(request); |
| 2034 | break; |
| 2035 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2036 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2037 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2038 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2039 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2040 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2041 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2042 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2043 | |
| 2044 | case CMD_SET_DATA_THROTTLING: { |
| 2045 | request = (MainThreadRequest) msg.obj; |
| 2046 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2047 | DataThrottlingRequest dataThrottlingRequest = |
| 2048 | (DataThrottlingRequest) request.argument; |
| 2049 | Phone phone = getPhoneFromRequest(request); |
| 2050 | if (phone != null) { |
| 2051 | phone.setDataThrottling(onCompleted, |
| 2052 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2053 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2054 | } else { |
| 2055 | loge("setDataThrottling: No phone object"); |
| 2056 | request.result = |
| 2057 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2058 | notifyRequester(request); |
| 2059 | } |
| 2060 | |
| 2061 | break; |
| 2062 | } |
| 2063 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2064 | ar = (AsyncResult) msg.obj; |
| 2065 | request = (MainThreadRequest) ar.userObj; |
| 2066 | |
| 2067 | if (ar.exception == null) { |
| 2068 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2069 | } else if (ar.exception instanceof CommandException) { |
| 2070 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2071 | CommandException.Error error = |
| 2072 | ((CommandException) (ar.exception)).getCommandError(); |
| 2073 | |
| 2074 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2075 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2076 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2077 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2078 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2079 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2080 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2081 | } else { |
| 2082 | request.result = |
| 2083 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2084 | } |
| 2085 | } else { |
| 2086 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2087 | } |
| 2088 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2089 | notifyRequester(request); |
| 2090 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2091 | |
| 2092 | case CMD_SET_SIM_POWER: { |
| 2093 | request = (MainThreadRequest) msg.obj; |
| 2094 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2095 | request = (MainThreadRequest) msg.obj; |
| 2096 | int stateToSet = |
| 2097 | ((Pair<Integer, IIntegerConsumer>) |
| 2098 | request.argument).first; |
| 2099 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2100 | break; |
| 2101 | } |
| 2102 | case EVENT_SET_SIM_POWER_DONE: { |
| 2103 | ar = (AsyncResult) msg.obj; |
| 2104 | request = (MainThreadRequest) ar.userObj; |
| 2105 | IIntegerConsumer callback = |
| 2106 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2107 | if (ar.exception != null) { |
| 2108 | loge("setSimPower exception: " + ar.exception); |
| 2109 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2110 | .RESULT_ERROR_UNKNOWN; |
| 2111 | if (ar.exception instanceof CommandException) { |
| 2112 | CommandException.Error error = |
| 2113 | ((CommandException) (ar.exception)).getCommandError(); |
| 2114 | if (error == CommandException.Error.SIM_ERR) { |
| 2115 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2116 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2117 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2118 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2119 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2120 | } else { |
| 2121 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2122 | } |
| 2123 | } |
| 2124 | try { |
| 2125 | callback.accept(errorCode); |
| 2126 | } catch (RemoteException e) { |
| 2127 | // Ignore if the remote process is no longer available to call back. |
| 2128 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2129 | } |
| 2130 | } else { |
| 2131 | try { |
| 2132 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2133 | } catch (RemoteException e) { |
| 2134 | // Ignore if the remote process is no longer available to call back. |
| 2135 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2136 | } |
| 2137 | } |
| 2138 | break; |
| 2139 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2140 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2141 | request = (MainThreadRequest) msg.obj; |
| 2142 | |
| 2143 | final Phone phone = getPhoneFromRequest(request); |
| 2144 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2145 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2146 | notifyRequester(request); |
| 2147 | break; |
| 2148 | } |
| 2149 | |
| 2150 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2151 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2152 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2153 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2154 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2155 | request.subId, pair.first /*callingUid*/, |
| 2156 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2157 | break; |
| 2158 | } |
| 2159 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2160 | ar = (AsyncResult) msg.obj; |
| 2161 | request = (MainThreadRequest) ar.userObj; |
| 2162 | // request.result will be the exception of ar if present, true otherwise. |
| 2163 | // Be cautious not to leave result null which will wait() forever |
| 2164 | request.result = ar.exception != null ? ar.exception : true; |
| 2165 | notifyRequester(request); |
| 2166 | break; |
| 2167 | } |
| 2168 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2169 | request = (MainThreadRequest) msg.obj; |
| 2170 | |
| 2171 | Phone phone = getPhoneFromRequest(request); |
| 2172 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2173 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2174 | notifyRequester(request); |
| 2175 | break; |
| 2176 | } |
| 2177 | |
| 2178 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2179 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2180 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2181 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2182 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2183 | request.subId, pair.first /*callingUid*/, |
| 2184 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2185 | break; |
| 2186 | } |
| 2187 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2188 | ar = (AsyncResult) msg.obj; |
| 2189 | request = (MainThreadRequest) ar.userObj; |
| 2190 | request.result = ar.exception != null ? ar.exception : true; |
| 2191 | notifyRequester(request); |
| 2192 | break; |
| 2193 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2194 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2195 | case CMD_GET_SLICING_CONFIG: { |
| 2196 | request = (MainThreadRequest) msg.obj; |
| 2197 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2198 | request.phone.getSlicingConfig(onCompleted); |
| 2199 | break; |
| 2200 | } |
| 2201 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2202 | ar = (AsyncResult) msg.obj; |
| 2203 | request = (MainThreadRequest) ar.userObj; |
| 2204 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2205 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2206 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2207 | Bundle bundle = new Bundle(); |
| 2208 | int resultCode = 0; |
| 2209 | if (ar.exception != null) { |
| 2210 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2211 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2212 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2213 | } else if (ar.result == null) { |
| 2214 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2215 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2216 | } else { |
| 2217 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2218 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2219 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2223 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2224 | } |
| 2225 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2226 | result.send(resultCode, bundle); |
| 2227 | notifyRequester(request); |
| 2228 | break; |
| 2229 | } |
| 2230 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2231 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2232 | request = (MainThreadRequest) msg.obj; |
| 2233 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2234 | PurchasePremiumCapabilityArgument arg = |
| 2235 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2236 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2237 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2238 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2239 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2240 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2241 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2242 | ar = (AsyncResult) msg.obj; |
| 2243 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2244 | PurchasePremiumCapabilityArgument arg = |
| 2245 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2246 | try { |
| 2247 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2248 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2249 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2250 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2251 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2252 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2253 | } catch (RemoteException e) { |
| 2254 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2255 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2256 | + " failed: " + e; |
| 2257 | if (DBG) log(logStr); |
| 2258 | AnomalyReporter.reportAnomaly( |
| 2259 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2260 | } |
| 2261 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2262 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2263 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2264 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2265 | request = (MainThreadRequest) msg.obj; |
| 2266 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2267 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2268 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2269 | notifyRequester(request); |
| 2270 | break; |
| 2271 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2272 | default: |
| 2273 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2274 | break; |
| 2275 | } |
| 2276 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2277 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2278 | private void notifyRequester(MainThreadRequest request) { |
| 2279 | synchronized (request) { |
| 2280 | request.notifyAll(); |
| 2281 | } |
| 2282 | } |
| 2283 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2284 | private void handleNullReturnEvent(Message msg, String command) { |
| 2285 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2286 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2287 | if (ar.exception == null) { |
| 2288 | request.result = true; |
| 2289 | } else { |
| 2290 | request.result = false; |
| 2291 | if (ar.exception instanceof CommandException) { |
| 2292 | loge(command + ": CommandException: " + ar.exception); |
| 2293 | } else { |
| 2294 | loge(command + ": Unknown exception"); |
| 2295 | } |
| 2296 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2297 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2298 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | /** |
| 2302 | * Posts the specified command to be executed on the main thread, |
| 2303 | * waits for the request to complete, and returns the result. |
| 2304 | * @see #sendRequestAsync |
| 2305 | */ |
| 2306 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2307 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2308 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -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, WorkSource workSource) { |
| 2317 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2318 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2326 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2327 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * Posts the specified command to be executed on the main thread, |
| 2332 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2333 | * if not timeout or null otherwise. |
| 2334 | * @see #sendRequestAsync |
| 2335 | */ |
| 2336 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2337 | long timeoutInMs) { |
| 2338 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | /** |
| 2342 | * Posts the specified command to be executed on the main thread, |
| 2343 | * waits for the request to complete, and returns the result. |
| 2344 | * @see #sendRequestAsync |
| 2345 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2346 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2347 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | /** |
| 2351 | * Posts the specified command to be executed on the main thread, |
| 2352 | * waits for the request to complete, and returns the result. |
| 2353 | * @see #sendRequestAsync |
| 2354 | */ |
| 2355 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2356 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2357 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2361 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2362 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2363 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2364 | * @see #sendRequestAsync |
| 2365 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2366 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2367 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2369 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2370 | } |
| 2371 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2372 | MainThreadRequest request = null; |
| 2373 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2374 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2375 | } else if (phone != null) { |
| 2376 | request = new MainThreadRequest(argument, phone, workSource); |
| 2377 | } else { |
| 2378 | request = new MainThreadRequest(argument, subId, workSource); |
| 2379 | } |
| 2380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2382 | msg.sendToTarget(); |
| 2383 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2384 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2385 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2386 | if (timeoutInMs >= 0) { |
| 2387 | // Wait for at least timeoutInMs before returning null request result |
| 2388 | long now = SystemClock.elapsedRealtime(); |
| 2389 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2390 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2391 | try { |
| 2392 | request.wait(deadline - now); |
| 2393 | } catch (InterruptedException e) { |
| 2394 | // Do nothing, go back and check if request is completed or timeout |
| 2395 | } finally { |
| 2396 | now = SystemClock.elapsedRealtime(); |
| 2397 | } |
| 2398 | } |
| 2399 | } else { |
| 2400 | // Wait for the request to complete |
| 2401 | while (request.result == null) { |
| 2402 | try { |
| 2403 | request.wait(); |
| 2404 | } catch (InterruptedException e) { |
| 2405 | // Do nothing, go back and wait until the request is complete |
| 2406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2410 | if (request.result == null) { |
| 2411 | Log.wtf(LOG_TAG, |
| 2412 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2413 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2414 | return request.result; |
| 2415 | } |
| 2416 | |
| 2417 | /** |
| 2418 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2419 | * Posts the specified command to be executed on the main thread, and |
| 2420 | * returns immediately. |
| 2421 | * @see #sendRequest |
| 2422 | */ |
| 2423 | private void sendRequestAsync(int command) { |
| 2424 | mMainThreadHandler.sendEmptyMessage(command); |
| 2425 | } |
| 2426 | |
| 2427 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2428 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2429 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2430 | */ |
| 2431 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2432 | sendRequestAsync(command, argument, null, null); |
| 2433 | } |
| 2434 | |
| 2435 | /** |
| 2436 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2437 | * @see {@link #sendRequest(int,Object)} |
| 2438 | */ |
| 2439 | private void sendRequestAsync( |
| 2440 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2441 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2442 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2443 | msg.sendToTarget(); |
| 2444 | } |
| 2445 | |
| 2446 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2447 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2448 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2449 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2450 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2451 | synchronized (PhoneInterfaceManager.class) { |
| 2452 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2453 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | } else { |
| 2455 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2456 | } |
| 2457 | return sInstance; |
| 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2462 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2464 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2465 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2466 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2467 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2468 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2470 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2471 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2472 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2473 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2474 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2475 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2476 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2477 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2478 | getDefaultPhone().getContext(), featureFlags); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2479 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2481 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2482 | |
| 2483 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2484 | // entitlementStatus for satellite service. |
| 2485 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2488 | @VisibleForTesting |
| 2489 | public SharedPreferences getSharedPreferences() { |
| 2490 | return mTelephonySharedPreferences; |
| 2491 | } |
| 2492 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2493 | /** |
| 2494 | * Get the default phone for this device. |
| 2495 | */ |
| 2496 | @VisibleForTesting |
| 2497 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2498 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2499 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2500 | } |
| 2501 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2502 | private void publish() { |
| 2503 | if (DBG) log("publish: " + this); |
| 2504 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2505 | TelephonyFrameworkInitializer |
| 2506 | .getTelephonyServiceManager() |
| 2507 | .getTelephonyServiceRegisterer() |
| 2508 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2511 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2512 | if (request.phone != null) { |
| 2513 | return request.phone; |
| 2514 | } else { |
| 2515 | return getPhoneFromSubId(request.subId); |
| 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | private Phone getPhoneFromSubId(int subId) { |
| 2520 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2521 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2522 | } |
| 2523 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2524 | /** |
| 2525 | * Get phone object associated with a subscription. |
| 2526 | * Return default phone if phone object associated with subscription is null |
| 2527 | * @param subId - subscriptionId |
| 2528 | * @return phone object associated with a subscription or default phone if null. |
| 2529 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2530 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2531 | Phone phone = getPhoneFromSubId(subId); |
| 2532 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2533 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2534 | phone = getDefaultPhone(); |
| 2535 | } |
| 2536 | return phone; |
| 2537 | } |
| 2538 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2539 | @Nullable |
| 2540 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2541 | Phone phone = getPhoneFromRequest(request); |
| 2542 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2543 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2544 | } |
| 2545 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2546 | /** |
| 2547 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2548 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2549 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2550 | * @return The Phone associated the sub Id |
| 2551 | */ |
| 2552 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2553 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2554 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2555 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2556 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2557 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2558 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2559 | } |
| 2560 | |
| 2561 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2562 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2563 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2566 | private boolean isImsAvailableOnDevice() { |
| 2567 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2568 | if (pm == null) { |
| 2569 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2570 | // so do not throw error and allow. |
| 2571 | return true; |
| 2572 | } |
| 2573 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2574 | } |
| 2575 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2577 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2578 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2579 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2580 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2583 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2584 | if (DBG) log("dial: " + number); |
| 2585 | // No permission check needed here: This is just a wrapper around the |
| 2586 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2587 | // the UI before it does anything. |
| 2588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2589 | final long identity = Binder.clearCallingIdentity(); |
| 2590 | try { |
| 2591 | String url = createTelUrl(number); |
| 2592 | if (url == null) { |
| 2593 | return; |
| 2594 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2596 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2597 | PhoneConstants.State state = mCM.getState(subId); |
| 2598 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2599 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2600 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2601 | mApp.startActivity(intent); |
| 2602 | } |
| 2603 | } finally { |
| 2604 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2609 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2610 | } |
| 2611 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2612 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | if (DBG) log("call: " + number); |
| 2614 | |
| 2615 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2616 | // need to do a permission check since we're calling startActivity() |
| 2617 | // from the context of the phone app. |
| 2618 | enforceCallPermission(); |
| 2619 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2620 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2621 | != AppOpsManager.MODE_ALLOWED) { |
| 2622 | return; |
| 2623 | } |
| 2624 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2625 | enforceTelephonyFeatureWithException(callingPackage, |
| 2626 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2627 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2628 | final long identity = Binder.clearCallingIdentity(); |
| 2629 | try { |
| 2630 | String url = createTelUrl(number); |
| 2631 | if (url == null) { |
| 2632 | return; |
| 2633 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2635 | boolean isValid = false; |
| 2636 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2637 | if (slist != null) { |
| 2638 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2639 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2640 | isValid = true; |
| 2641 | break; |
| 2642 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2643 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2644 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2645 | if (!isValid) { |
| 2646 | return; |
| 2647 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2648 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2650 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2651 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2652 | mApp.startActivity(intent); |
| 2653 | } finally { |
| 2654 | Binder.restoreCallingIdentity(identity); |
| 2655 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2658 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2659 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2660 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2661 | } |
| 2662 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2663 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2664 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2665 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2666 | } |
| 2667 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2668 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2669 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2670 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2671 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2672 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2673 | "supplyPinReportResultForSubscriber"); |
| 2674 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2675 | final long identity = Binder.clearCallingIdentity(); |
| 2676 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2677 | Phone phone = getPhone(subId); |
| 2678 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | checkSimPin.start(); |
| 2680 | return checkSimPin.unlockSim(null, pin); |
| 2681 | } finally { |
| 2682 | Binder.restoreCallingIdentity(identity); |
| 2683 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2686 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2689 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2690 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2691 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2692 | final long identity = Binder.clearCallingIdentity(); |
| 2693 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2694 | Phone phone = getPhone(subId); |
| 2695 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2696 | checkSimPuk.start(); |
| 2697 | return checkSimPuk.unlockSim(puk, pin); |
| 2698 | } finally { |
| 2699 | Binder.restoreCallingIdentity(identity); |
| 2700 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2704 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | * a synchronous one. |
| 2706 | */ |
| 2707 | private static class UnlockSim extends Thread { |
| 2708 | |
| 2709 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2710 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2711 | |
| 2712 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2713 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2714 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | |
| 2716 | // For replies from SimCard interface |
| 2717 | private Handler mHandler; |
| 2718 | |
| 2719 | // For async handler to identify request type |
| 2720 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2721 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2722 | UnlockSim(int phoneId, IccCard simCard) { |
| 2723 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | mSimCard = simCard; |
| 2725 | } |
| 2726 | |
| 2727 | @Override |
| 2728 | public void run() { |
| 2729 | Looper.prepare(); |
| 2730 | synchronized (UnlockSim.this) { |
| 2731 | mHandler = new Handler() { |
| 2732 | @Override |
| 2733 | public void handleMessage(Message msg) { |
| 2734 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2735 | switch (msg.what) { |
| 2736 | case SUPPLY_PIN_COMPLETE: |
| 2737 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2738 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2739 | mRetryCount = msg.arg1; |
| 2740 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2741 | CommandException.Error error = null; |
| 2742 | if (ar.exception instanceof CommandException) { |
| 2743 | error = ((CommandException) (ar.exception)) |
| 2744 | .getCommandError(); |
| 2745 | } |
| 2746 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2747 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2748 | } else if (error == CommandException.Error.ABORTED) { |
| 2749 | /* When UiccCardApp dispose, handle message and return |
| 2750 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2751 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2752 | } else { |
| 2753 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2754 | } |
| 2755 | } else { |
| 2756 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2757 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2758 | mDone = true; |
| 2759 | UnlockSim.this.notifyAll(); |
| 2760 | } |
| 2761 | break; |
| 2762 | } |
| 2763 | } |
| 2764 | }; |
| 2765 | UnlockSim.this.notifyAll(); |
| 2766 | } |
| 2767 | Looper.loop(); |
| 2768 | } |
| 2769 | |
| 2770 | /* |
| 2771 | * Use PIN or PUK to unlock SIM card |
| 2772 | * |
| 2773 | * If PUK is null, unlock SIM card with PIN |
| 2774 | * |
| 2775 | * 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] | 2776 | * |
| 2777 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2778 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2780 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2781 | |
| 2782 | while (mHandler == null) { |
| 2783 | try { |
| 2784 | wait(); |
| 2785 | } catch (InterruptedException e) { |
| 2786 | Thread.currentThread().interrupt(); |
| 2787 | } |
| 2788 | } |
| 2789 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2790 | |
| 2791 | if (puk == null) { |
| 2792 | mSimCard.supplyPin(pin, callback); |
| 2793 | } else { |
| 2794 | mSimCard.supplyPuk(puk, pin, callback); |
| 2795 | } |
| 2796 | |
| 2797 | while (!mDone) { |
| 2798 | try { |
| 2799 | Log.d(LOG_TAG, "wait for done"); |
| 2800 | wait(); |
| 2801 | } catch (InterruptedException e) { |
| 2802 | // Restore the interrupted status |
| 2803 | Thread.currentThread().interrupt(); |
| 2804 | } |
| 2805 | } |
| 2806 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2807 | int[] resultArray = new int[2]; |
| 2808 | resultArray[0] = mResult; |
| 2809 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2810 | |
| 2811 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2812 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2813 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2814 | // This instance is no longer reused, so quit its thread's looper. |
| 2815 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2816 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2817 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2818 | } |
| 2819 | } |
| 2820 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2821 | /** |
| 2822 | * This method has been removed due to privacy and stability concerns. |
| 2823 | */ |
| 2824 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2826 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2827 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2830 | @Override |
| 2831 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2832 | mApp.getSystemService(AppOpsManager.class) |
| 2833 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2834 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2835 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2836 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2837 | // Callers targeting S have no business invoking this method. |
| 2838 | return; |
| 2839 | } |
| 2840 | |
| 2841 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2842 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2843 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2844 | .setCallingPackage(callingPackage) |
| 2845 | .setCallingFeatureId(null) |
| 2846 | .setCallingPid(Binder.getCallingPid()) |
| 2847 | .setCallingUid(Binder.getCallingUid()) |
| 2848 | .setMethod("updateServiceLocation") |
| 2849 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2850 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2851 | .build()); |
| 2852 | // Apps that lack location permission have no business calling this method; |
| 2853 | // however, because no permission was declared in the public API, denials must |
| 2854 | // all be "soft". |
| 2855 | switch (locationResult) { |
| 2856 | case DENIED_HARD: /* fall through */ |
| 2857 | case DENIED_SOFT: |
| 2858 | return; |
| 2859 | } |
| 2860 | |
| 2861 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | final long identity = Binder.clearCallingIdentity(); |
| 2863 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2864 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2867 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2870 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2871 | @Override |
| 2872 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2873 | return isRadioOnWithFeature(callingPackage, null); |
| 2874 | } |
| 2875 | |
| 2876 | |
| 2877 | @Override |
| 2878 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2879 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2880 | callingFeatureId); |
| 2881 | } |
| 2882 | |
| 2883 | @Deprecated |
| 2884 | @Override |
| 2885 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2886 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2889 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2890 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2891 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2893 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2894 | return false; |
| 2895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2896 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2897 | enforceTelephonyFeatureWithException(callingPackage, |
| 2898 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2899 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | return isRadioOnForSubscriber(subId); |
| 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(identity); |
| 2905 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2909 | final long identity = Binder.clearCallingIdentity(); |
| 2910 | try { |
| 2911 | final Phone phone = getPhone(subId); |
| 2912 | if (phone != null) { |
| 2913 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2914 | } else { |
| 2915 | return false; |
| 2916 | } |
| 2917 | } finally { |
| 2918 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2919 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2923 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2924 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2925 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2926 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2927 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2928 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2929 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2930 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2931 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | final Phone phone = getPhone(subId); |
| 2935 | if (phone != null) { |
| 2936 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2937 | } |
| 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2940 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2944 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2947 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2948 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2949 | |
| 2950 | final long identity = Binder.clearCallingIdentity(); |
| 2951 | try { |
| 2952 | final Phone phone = getPhone(subId); |
| 2953 | if (phone == null) { |
| 2954 | return false; |
| 2955 | } |
| 2956 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2957 | toggleRadioOnOffForSubscriber(subId); |
| 2958 | } |
| 2959 | return true; |
| 2960 | } finally { |
| 2961 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2962 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2963 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2964 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2965 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2966 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2967 | |
| 2968 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2969 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2970 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2971 | /* |
| 2972 | * If any of the Radios are available, it will need to be |
| 2973 | * shutdown. So return true if any Radio is available. |
| 2974 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2975 | final long identity = Binder.clearCallingIdentity(); |
| 2976 | try { |
| 2977 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2978 | Phone phone = PhoneFactory.getPhone(i); |
| 2979 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2980 | } |
| 2981 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2982 | return false; |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2985 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2988 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2989 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2990 | enforceModifyPermission(); |
| 2991 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2992 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2993 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 2994 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
| 2997 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2998 | logv("Shutting down Phone " + i); |
| 2999 | shutdownRadioUsingPhoneId(i); |
| 3000 | } |
| 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3007 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3008 | if (phone != null && phone.isRadioAvailable()) { |
| 3009 | phone.shutdownRadio(); |
| 3010 | } |
| 3011 | } |
| 3012 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3013 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3014 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3016 | if (!turnOn) { |
| 3017 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3018 | } |
| 3019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3023 | if (defaultPhone != null) { |
| 3024 | defaultPhone.setRadioPower(turnOn); |
| 3025 | return true; |
| 3026 | } else { |
| 3027 | loge("There's no default phone."); |
| 3028 | return false; |
| 3029 | } |
| 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3032 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3035 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3036 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3037 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3038 | if (!turnOn) { |
| 3039 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3040 | + ",callingPackage=" + getCurrentPackageName()); |
| 3041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3042 | final long identity = Binder.clearCallingIdentity(); |
| 3043 | try { |
| 3044 | final Phone phone = getPhone(subId); |
| 3045 | if (phone != null) { |
| 3046 | phone.setRadioPower(turnOn); |
| 3047 | return true; |
| 3048 | } else { |
| 3049 | return false; |
| 3050 | } |
| 3051 | } finally { |
| 3052 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3053 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3054 | } |
| 3055 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3056 | /** |
| 3057 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3058 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3059 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3060 | * powering it off, and these radio off votes will be cleared. |
| 3061 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3062 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3063 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3064 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3065 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3066 | * check its vote. |
| 3067 | * |
| 3068 | * @param subId The subscription ID. |
| 3069 | * @param reason The reason for powering off radio. |
| 3070 | * @return true on success and false on failure. |
| 3071 | */ |
| 3072 | public boolean requestRadioPowerOffForReason(int subId, |
| 3073 | @TelephonyManager.RadioPowerReason int reason) { |
| 3074 | enforceModifyPermission(); |
| 3075 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3076 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3077 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3078 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3079 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3080 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3083 | boolean result = false; |
| 3084 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3085 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3086 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3087 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3088 | if (!result) { |
| 3089 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3090 | } |
| 3091 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(identity); |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | /** |
| 3098 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3099 | * {@link requestRadioPowerOffForReason}. |
| 3100 | * |
| 3101 | * @param subId The subscription ID. |
| 3102 | * @param reason The reason for powering off radio. |
| 3103 | * @return true on success and false on failure. |
| 3104 | */ |
| 3105 | public boolean clearRadioPowerOffForReason(int subId, |
| 3106 | @TelephonyManager.RadioPowerReason int reason) { |
| 3107 | enforceModifyPermission(); |
| 3108 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3109 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3110 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3111 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3112 | final long identity = Binder.clearCallingIdentity(); |
| 3113 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3114 | boolean result = false; |
| 3115 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3116 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3117 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3118 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3119 | if (!result) { |
| 3120 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3121 | } |
| 3122 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3123 | } finally { |
| 3124 | Binder.restoreCallingIdentity(identity); |
| 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | /** |
| 3129 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3130 | * |
| 3131 | * @param subId The subscription ID. |
| 3132 | * @param callingPackage The package making the call. |
| 3133 | * @param callingFeatureId The feature in the package. |
| 3134 | * @return List of reasons for powering off radio. |
| 3135 | */ |
| 3136 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3137 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3138 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3139 | enforceTelephonyFeatureWithException(callingPackage, |
| 3140 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3141 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3142 | final long identity = Binder.clearCallingIdentity(); |
| 3143 | List result = new ArrayList(); |
| 3144 | try { |
| 3145 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3146 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3147 | return result; |
| 3148 | } |
| 3149 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3150 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3151 | if (phone != null) { |
| 3152 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3153 | } else { |
| 3154 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3155 | } |
| 3156 | } finally { |
| 3157 | Binder.restoreCallingIdentity(identity); |
| 3158 | } |
| 3159 | return result; |
| 3160 | } |
| 3161 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3162 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3163 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3164 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3165 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3166 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3167 | enforceTelephonyFeatureWithException(callingPackage, |
| 3168 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3169 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3170 | final long identity = Binder.clearCallingIdentity(); |
| 3171 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3172 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3173 | final Phone phone = getPhone(subId); |
| 3174 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3175 | phone.getDataSettingsManager().setDataEnabled( |
| 3176 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3177 | return true; |
| 3178 | } else { |
| 3179 | return false; |
| 3180 | } |
| 3181 | } finally { |
| 3182 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3183 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3186 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3187 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3188 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3189 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3191 | enforceTelephonyFeatureWithException(callingPackage, |
| 3192 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3193 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | final long identity = Binder.clearCallingIdentity(); |
| 3195 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3196 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3197 | final Phone phone = getPhone(subId); |
| 3198 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3199 | phone.getDataSettingsManager().setDataEnabled( |
| 3200 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | return true; |
| 3202 | } else { |
| 3203 | return false; |
| 3204 | } |
| 3205 | } finally { |
| 3206 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3207 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3208 | } |
| 3209 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3210 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3211 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3212 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3213 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3215 | final long identity = Binder.clearCallingIdentity(); |
| 3216 | try { |
| 3217 | final Phone phone = getPhone(subId); |
| 3218 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3219 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3220 | } else { |
| 3221 | return false; |
| 3222 | } |
| 3223 | } finally { |
| 3224 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3225 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3229 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3232 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | enforceCallPermission(); |
| 3234 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3235 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3236 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3237 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3238 | final long identity = Binder.clearCallingIdentity(); |
| 3239 | try { |
| 3240 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3241 | return; |
| 3242 | } |
| 3243 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3244 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3245 | } finally { |
| 3246 | Binder.restoreCallingIdentity(identity); |
| 3247 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3248 | }; |
| 3249 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3250 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3251 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3253 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3254 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3255 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3256 | final long identity = Binder.clearCallingIdentity(); |
| 3257 | try { |
| 3258 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3259 | return false; |
| 3260 | } |
| 3261 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3262 | } finally { |
| 3263 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3264 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3267 | /** |
| 3268 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3269 | * tag on getCallState Binder call. |
| 3270 | */ |
| 3271 | @Deprecated |
| 3272 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3273 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3274 | if (CompatChanges.isChangeEnabled( |
| 3275 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3276 | Binder.getCallingUid())) { |
| 3277 | // Do not allow this API to be called on API version 31+, it should only be |
| 3278 | // called on old apps using this Binder call directly. |
| 3279 | throw new SecurityException("This method can only be used for applications " |
| 3280 | + "targeting API version 30 or less."); |
| 3281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | final long identity = Binder.clearCallingIdentity(); |
| 3283 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3284 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3285 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3286 | } finally { |
| 3287 | Binder.restoreCallingIdentity(identity); |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | @Override |
| 3292 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3293 | if (CompatChanges.isChangeEnabled( |
| 3294 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3295 | Binder.getCallingUid())) { |
| 3296 | // Check READ_PHONE_STATE for API version 31+ |
| 3297 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3298 | featureId, "getCallStateForSubscription")) { |
| 3299 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3300 | + "targeting API level 31+."); |
| 3301 | } |
| 3302 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3303 | |
| 3304 | enforceTelephonyFeatureWithException(callingPackage, |
| 3305 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3306 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3307 | final long identity = Binder.clearCallingIdentity(); |
| 3308 | try { |
| 3309 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3310 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3311 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3312 | } finally { |
| 3313 | Binder.restoreCallingIdentity(identity); |
| 3314 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3317 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3318 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3319 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | @Override |
| 3323 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3324 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3325 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3326 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3327 | final long identity = Binder.clearCallingIdentity(); |
| 3328 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3329 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3331 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3332 | } else { |
| 3333 | return PhoneConstantConversions.convertDataState( |
| 3334 | PhoneConstants.DataState.DISCONNECTED); |
| 3335 | } |
| 3336 | } finally { |
| 3337 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3338 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3341 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3342 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3343 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3347 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3348 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3349 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3350 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3351 | final long identity = Binder.clearCallingIdentity(); |
| 3352 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3353 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3354 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3355 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3356 | } else { |
| 3357 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3358 | } |
| 3359 | } finally { |
| 3360 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3361 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3365 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3366 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3367 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3368 | |
| 3369 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3370 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3371 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3372 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3373 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3374 | .setCallingPid(Binder.getCallingPid()) |
| 3375 | .setCallingUid(Binder.getCallingUid()) |
| 3376 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3377 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3378 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3379 | .build()); |
| 3380 | switch (locationResult) { |
| 3381 | case DENIED_HARD: |
| 3382 | throw new SecurityException("Not allowed to access cell location"); |
| 3383 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3384 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3385 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3386 | } |
| 3387 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3388 | enforceTelephonyFeatureWithException(callingPackage, |
| 3389 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3390 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3391 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | final long identity = Binder.clearCallingIdentity(); |
| 3393 | try { |
| 3394 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3395 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3396 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3397 | } finally { |
| 3398 | Binder.restoreCallingIdentity(identity); |
| 3399 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3402 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3403 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3404 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3405 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3406 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3407 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3408 | // registered cell info, so return a NULL country instead. |
| 3409 | final long identity = Binder.clearCallingIdentity(); |
| 3410 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3411 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3412 | // Get default phone in this case. |
| 3413 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3414 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3415 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3416 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3417 | if (phone == null) return ""; |
| 3418 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3419 | if (sst == null) return ""; |
| 3420 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3421 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3422 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3423 | } finally { |
| 3424 | Binder.restoreCallingIdentity(identity); |
| 3425 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3428 | /** |
| 3429 | * This method was removed due to potential issues caused by performing partial |
| 3430 | * updates of service state, and lack of a credible use case. |
| 3431 | * |
| 3432 | * This has the ability to break the telephony implementation by disabling notification of |
| 3433 | * changes in device connectivity. DO NOT USE THIS! |
| 3434 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3435 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3436 | public void enableLocationUpdates() { |
| 3437 | mApp.enforceCallingOrSelfPermission( |
| 3438 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3441 | /** |
| 3442 | * This method was removed due to potential issues caused by performing partial |
| 3443 | * updates of service state, and lack of a credible use case. |
| 3444 | * |
| 3445 | * This has the ability to break the telephony implementation by disabling notification of |
| 3446 | * changes in device connectivity. DO NOT USE THIS! |
| 3447 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3448 | @Override |
| 3449 | public void disableLocationUpdates() { |
| 3450 | mApp.enforceCallingOrSelfPermission( |
| 3451 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | @Override |
| 3455 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3456 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3457 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3458 | try { |
| 3459 | mApp.getSystemService(AppOpsManager.class) |
| 3460 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3461 | } catch (SecurityException e) { |
| 3462 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3463 | throw e; |
| 3464 | } |
| 3465 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3466 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3467 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3468 | throw new SecurityException( |
| 3469 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3470 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3471 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3472 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3473 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3474 | return null; |
| 3475 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3476 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3477 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3478 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3479 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3480 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3481 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3482 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3483 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3484 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3485 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3486 | for (CellInfo ci : info) { |
| 3487 | if (ci instanceof CellInfoGsm) { |
| 3488 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3489 | } else if (ci instanceof CellInfoWcdma) { |
| 3490 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3491 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3492 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3493 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3496 | private List<CellInfo> getCachedCellInfo() { |
| 3497 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3498 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3499 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3500 | if (info != null) cellInfos.addAll(info); |
| 3501 | } |
| 3502 | return cellInfos; |
| 3503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3504 | |
| 3505 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3506 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3507 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3508 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3509 | |
| 3510 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3511 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3512 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3513 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3514 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3515 | .setCallingPid(Binder.getCallingPid()) |
| 3516 | .setCallingUid(Binder.getCallingUid()) |
| 3517 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3518 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3519 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3520 | .build()); |
| 3521 | switch (locationResult) { |
| 3522 | case DENIED_HARD: |
| 3523 | throw new SecurityException("Not allowed to access cell info"); |
| 3524 | case DENIED_SOFT: |
| 3525 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3528 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3529 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3530 | return getCachedCellInfo(); |
| 3531 | } |
| 3532 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3533 | enforceTelephonyFeatureWithException(callingPackage, |
| 3534 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3535 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3536 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3537 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3538 | final long identity = Binder.clearCallingIdentity(); |
| 3539 | try { |
| 3540 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3541 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3542 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3543 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3544 | if (info != null) cellInfos.addAll(info); |
| 3545 | } |
| 3546 | return cellInfos; |
| 3547 | } finally { |
| 3548 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3549 | } |
| 3550 | } |
| 3551 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3552 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3553 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3554 | String callingFeatureId) { |
| 3555 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3556 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3560 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3561 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3562 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3563 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3566 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3567 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3568 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3569 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3570 | |
| 3571 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3572 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3573 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3574 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3575 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3576 | .setCallingPid(Binder.getCallingPid()) |
| 3577 | .setCallingUid(Binder.getCallingUid()) |
| 3578 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3579 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3580 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3581 | .build()); |
| 3582 | switch (locationResult) { |
| 3583 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3584 | if (TelephonyPermissions |
| 3585 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3586 | // Safetynet logging for b/154934934 |
| 3587 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3588 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3589 | throw new SecurityException("Not allowed to access cell info"); |
| 3590 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3591 | if (TelephonyPermissions |
| 3592 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3593 | // Safetynet logging for b/154934934 |
| 3594 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3595 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3596 | try { |
| 3597 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3598 | } catch (RemoteException re) { |
| 3599 | // Drop without consequences |
| 3600 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3601 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3602 | } |
| 3603 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3604 | enforceTelephonyFeatureWithException(callingPackage, |
| 3605 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3606 | |
| 3607 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3608 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3609 | |
| 3610 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3611 | } |
| 3612 | |
| 3613 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3614 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3615 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3616 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3617 | |
| 3618 | final long identity = Binder.clearCallingIdentity(); |
| 3619 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3620 | Phone phone = getPhone(subId); |
| 3621 | if (phone == null) { |
| 3622 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3623 | } else { |
| 3624 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3625 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3626 | } finally { |
| 3627 | Binder.restoreCallingIdentity(identity); |
| 3628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3631 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3632 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3633 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3634 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3635 | return null; |
| 3636 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3637 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3638 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3639 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3640 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3641 | return null; |
| 3642 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3643 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3644 | enforceTelephonyFeatureWithException(callingPackage, |
| 3645 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3647 | final long identity = Binder.clearCallingIdentity(); |
| 3648 | try { |
| 3649 | return phone.getImei(); |
| 3650 | } finally { |
| 3651 | Binder.restoreCallingIdentity(identity); |
| 3652 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3656 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3657 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3658 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3659 | callingFeatureId, "getPrimaryImei")) { |
| 3660 | throw new SecurityException("Caller does not have permission"); |
| 3661 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3662 | |
| 3663 | enforceTelephonyFeatureWithException(callingPackage, |
| 3664 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3665 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3669 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3670 | return phone.getImei(); |
| 3671 | } |
| 3672 | } |
| 3673 | throw new UnsupportedOperationException("Operation not supported"); |
| 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(identity); |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3680 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3681 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3682 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3683 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3684 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3685 | String tac = null; |
| 3686 | if (phone != null) { |
| 3687 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3688 | try { |
| 3689 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3690 | } catch (IndexOutOfBoundsException e) { |
| 3691 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3692 | return null; |
| 3693 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3694 | } |
| 3695 | return tac; |
| 3696 | } |
| 3697 | |
| 3698 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3699 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3700 | try { |
| 3701 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3702 | } catch (SecurityException se) { |
| 3703 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3704 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3705 | + Binder.getCallingUid()); |
| 3706 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3707 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3708 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3709 | return null; |
| 3710 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3711 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3712 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3713 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3714 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3715 | return null; |
| 3716 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3717 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3718 | enforceTelephonyFeatureWithException(callingPackage, |
| 3719 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3720 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3721 | final long identity = Binder.clearCallingIdentity(); |
| 3722 | try { |
| 3723 | return phone.getMeid(); |
| 3724 | } finally { |
| 3725 | Binder.restoreCallingIdentity(identity); |
| 3726 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3730 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3731 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3732 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3733 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3734 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3735 | String manufacturerCode = null; |
| 3736 | if (phone != null) { |
| 3737 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3738 | try { |
| 3739 | manufacturerCode = |
| 3740 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3741 | } catch (IndexOutOfBoundsException e) { |
| 3742 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3743 | return null; |
| 3744 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3745 | } |
| 3746 | return manufacturerCode; |
| 3747 | } |
| 3748 | |
| 3749 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3750 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3751 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3752 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3753 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3754 | return null; |
| 3755 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3756 | int subId = phone.getSubId(); |
| 3757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3758 | mApp, subId, callingPackage, callingFeatureId, |
| 3759 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3760 | return null; |
| 3761 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3762 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3763 | enforceTelephonyFeatureWithException(callingPackage, |
| 3764 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3765 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | final long identity = Binder.clearCallingIdentity(); |
| 3767 | try { |
| 3768 | return phone.getDeviceSvn(); |
| 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(identity); |
| 3771 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3774 | @Override |
| 3775 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3776 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3777 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3778 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3779 | final long identity = Binder.clearCallingIdentity(); |
| 3780 | try { |
| 3781 | final Phone phone = getPhone(subId); |
| 3782 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3783 | } finally { |
| 3784 | Binder.restoreCallingIdentity(identity); |
| 3785 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | @Override |
| 3789 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3790 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3791 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3792 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3793 | final long identity = Binder.clearCallingIdentity(); |
| 3794 | try { |
| 3795 | final Phone phone = getPhone(subId); |
| 3796 | return phone == null ? null : phone.getCarrierName(); |
| 3797 | } finally { |
| 3798 | Binder.restoreCallingIdentity(identity); |
| 3799 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3800 | } |
| 3801 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3802 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3803 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3804 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3805 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3806 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -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 |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3811 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3812 | } finally { |
| 3813 | Binder.restoreCallingIdentity(identity); |
| 3814 | } |
| 3815 | } |
| 3816 | |
| 3817 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3818 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3819 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3820 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3821 | "getSubscriptionSpecificCarrierName"); |
| 3822 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3823 | final long identity = Binder.clearCallingIdentity(); |
| 3824 | try { |
| 3825 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3826 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(identity); |
| 3829 | } |
| 3830 | } |
| 3831 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3832 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3833 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3834 | if (!isSubscriptionMccMnc) { |
| 3835 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3836 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3837 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3838 | if (phone == null) { |
| 3839 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3840 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3841 | |
| 3842 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3843 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3844 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3848 | } finally { |
| 3849 | Binder.restoreCallingIdentity(identity); |
| 3850 | } |
| 3851 | } |
| 3852 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3853 | // |
| 3854 | // Internal helper methods. |
| 3855 | // |
| 3856 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3857 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3858 | * Make sure the caller is the calling package itself |
| 3859 | * |
| 3860 | * @throws SecurityException if the caller is not the calling package |
| 3861 | */ |
| 3862 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3863 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3864 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3865 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3866 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3867 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3868 | } catch (PackageManager.NameNotFoundException e) { |
| 3869 | // packageUid is -1 |
| 3870 | } |
| 3871 | if (packageUid != callingUid) { |
| 3872 | throw new SecurityException(message + ": Package " + callingPackage |
| 3873 | + " does not belong to " + callingUid); |
| 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3878 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3879 | * |
| 3880 | * @throws SecurityException if the caller does not have the required permission |
| 3881 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3882 | @VisibleForTesting |
| 3883 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3884 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3885 | } |
| 3886 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3887 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3888 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3889 | * |
| 3890 | * @throws SecurityException if the caller does not have the required permission |
| 3891 | */ |
| 3892 | @VisibleForTesting |
| 3893 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3894 | enforceReadPermission(null); |
| 3895 | } |
| 3896 | |
| 3897 | /** |
| 3898 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3899 | * |
| 3900 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3901 | */ |
| 3902 | @VisibleForTesting |
| 3903 | public void enforceReadPermission(String msg) { |
| 3904 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3905 | } |
| 3906 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3907 | private void enforceActiveEmergencySessionPermission() { |
| 3908 | mApp.enforceCallingOrSelfPermission( |
| 3909 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3910 | } |
| 3911 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3912 | /** |
| 3913 | * Make sure the caller has the CALL_PHONE permission. |
| 3914 | * |
| 3915 | * @throws SecurityException if the caller does not have the required permission |
| 3916 | */ |
| 3917 | private void enforceCallPermission() { |
| 3918 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3919 | } |
| 3920 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3921 | private void enforceSettingsPermission() { |
| 3922 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3925 | private void enforceRebootPermission() { |
| 3926 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3927 | } |
| 3928 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3929 | /** |
| 3930 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3931 | * @param message - log message to print. |
| 3932 | * @throws SecurityException if the caller does not have the required permission |
| 3933 | */ |
| 3934 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3935 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3936 | } |
| 3937 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3938 | private String createTelUrl(String number) { |
| 3939 | if (TextUtils.isEmpty(number)) { |
| 3940 | return null; |
| 3941 | } |
| 3942 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3943 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3946 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3947 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3950 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3951 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3954 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3955 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3956 | } |
| 3957 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3958 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3959 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3960 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3963 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3964 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3965 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3966 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 3967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3971 | if (phone == null) { |
| 3972 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3973 | } else { |
| 3974 | return phone.getPhoneType(); |
| 3975 | } |
| 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3978 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | /** |
| 3982 | * Returns the CDMA ERI icon index to display |
| 3983 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3984 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3985 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3986 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3987 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3988 | } |
| 3989 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3990 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3991 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3992 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3993 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3994 | mApp, subId, callingPackage, callingFeatureId, |
| 3995 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3996 | return -1; |
| 3997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3999 | enforceTelephonyFeatureWithException(callingPackage, |
| 4000 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4001 | "getCdmaEriIconIndexForSubscriber"); |
| 4002 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4003 | final long identity = Binder.clearCallingIdentity(); |
| 4004 | try { |
| 4005 | final Phone phone = getPhone(subId); |
| 4006 | if (phone != null) { |
| 4007 | return phone.getCdmaEriIconIndex(); |
| 4008 | } else { |
| 4009 | return -1; |
| 4010 | } |
| 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4013 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | /** |
| 4017 | * Returns the CDMA ERI icon mode, |
| 4018 | * 0 - ON |
| 4019 | * 1 - FLASHING |
| 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 getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4023 | return getCdmaEriIconModeForSubscriber(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 getCdmaEriIconModeForSubscriber(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 | "getCdmaEriIconModeForSubscriber")) { |
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 | |
| 4036 | final long identity = Binder.clearCallingIdentity(); |
| 4037 | try { |
| 4038 | final Phone phone = getPhone(subId); |
| 4039 | if (phone != null) { |
| 4040 | return phone.getCdmaEriIconMode(); |
| 4041 | } else { |
| 4042 | return -1; |
| 4043 | } |
| 4044 | } finally { |
| 4045 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4046 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | /** |
| 4050 | * Returns the CDMA ERI text, |
| 4051 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4052 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4053 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4054 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4055 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4056 | } |
| 4057 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4058 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4059 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4060 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4061 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4062 | mApp, subId, callingPackage, callingFeatureId, |
| 4063 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4064 | return null; |
| 4065 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4066 | |
| 4067 | final long identity = Binder.clearCallingIdentity(); |
| 4068 | try { |
| 4069 | final Phone phone = getPhone(subId); |
| 4070 | if (phone != null) { |
| 4071 | return phone.getCdmaEriText(); |
| 4072 | } else { |
| 4073 | return null; |
| 4074 | } |
| 4075 | } finally { |
| 4076 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4077 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4081 | * Returns the CDMA MDN. |
| 4082 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4083 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4084 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4085 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4086 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4087 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4088 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4089 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4091 | final long identity = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4094 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | return phone.getLine1Number(); |
| 4096 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4097 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4098 | return null; |
| 4099 | } |
| 4100 | } finally { |
| 4101 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | /** |
| 4106 | * Returns the CDMA MIN. |
| 4107 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4108 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4109 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4111 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4113 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4114 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4115 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4116 | final long identity = Binder.clearCallingIdentity(); |
| 4117 | try { |
| 4118 | final Phone phone = getPhone(subId); |
| 4119 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4120 | return phone.getCdmaMin(); |
| 4121 | } else { |
| 4122 | return null; |
| 4123 | } |
| 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4126 | } |
| 4127 | } |
| 4128 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4129 | @Override |
| 4130 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4131 | INumberVerificationCallback callback, String callingPackage) { |
| 4132 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4133 | != PERMISSION_GRANTED) { |
| 4134 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4135 | } |
| 4136 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4137 | |
| 4138 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4139 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4140 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4141 | + "calling package: " + callingPackage |
| 4142 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4143 | } |
| 4144 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4145 | enforceTelephonyFeatureWithException(callingPackage, |
| 4146 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4147 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4148 | if (range == null) { |
| 4149 | throw new NullPointerException("Range must be non-null"); |
| 4150 | } |
| 4151 | |
| 4152 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4153 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4154 | |
| 4155 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4156 | } |
| 4157 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4158 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4159 | * Returns true if CDMA provisioning needs to run. |
| 4160 | */ |
| 4161 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4162 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4163 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4165 | final long identity = Binder.clearCallingIdentity(); |
| 4166 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4167 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4168 | } finally { |
| 4169 | Binder.restoreCallingIdentity(identity); |
| 4170 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4174 | * Sets the voice mail number of a given subId. |
| 4175 | */ |
| 4176 | @Override |
| 4177 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4178 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4179 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4180 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4181 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4182 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4183 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4184 | final long identity = Binder.clearCallingIdentity(); |
| 4185 | try { |
| 4186 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4187 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4188 | return success; |
| 4189 | } finally { |
| 4190 | Binder.restoreCallingIdentity(identity); |
| 4191 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4192 | } |
| 4193 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4194 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4195 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4196 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4197 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4198 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4199 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4200 | throw new SecurityException("caller must be system dialer"); |
| 4201 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4202 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4203 | enforceTelephonyFeatureWithException(callingPackage, |
| 4204 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4205 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4206 | final long identity = Binder.clearCallingIdentity(); |
| 4207 | try { |
| 4208 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4209 | if (phoneAccountHandle == null) { |
| 4210 | return null; |
| 4211 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4212 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4215 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4219 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4220 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4221 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4222 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4223 | mApp, subId, callingPackage, callingFeatureId, |
| 4224 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4225 | return null; |
| 4226 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4227 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4228 | enforceTelephonyFeatureWithException(callingPackage, |
| 4229 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4230 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4233 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4234 | } finally { |
| 4235 | Binder.restoreCallingIdentity(identity); |
| 4236 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4240 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4241 | VisualVoicemailSmsFilterSettings settings) { |
| 4242 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4243 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4244 | enforceTelephonyFeatureWithException(callingPackage, |
| 4245 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
| 4246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | final long identity = Binder.clearCallingIdentity(); |
| 4248 | try { |
| 4249 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4250 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | } finally { |
| 4252 | Binder.restoreCallingIdentity(identity); |
| 4253 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4257 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4258 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4260 | enforceTelephonyFeatureWithException(callingPackage, |
| 4261 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4263 | final long identity = Binder.clearCallingIdentity(); |
| 4264 | try { |
| 4265 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4266 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4267 | } finally { |
| 4268 | Binder.restoreCallingIdentity(identity); |
| 4269 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4273 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4274 | String callingPackage, int subId) { |
| 4275 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4276 | |
| 4277 | final long identity = Binder.clearCallingIdentity(); |
| 4278 | try { |
| 4279 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4280 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4281 | } finally { |
| 4282 | Binder.restoreCallingIdentity(identity); |
| 4283 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4287 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4288 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4289 | |
| 4290 | final long identity = Binder.clearCallingIdentity(); |
| 4291 | try { |
| 4292 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4293 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | } finally { |
| 4295 | Binder.restoreCallingIdentity(identity); |
| 4296 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4300 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4301 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4302 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4303 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4304 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4305 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4306 | |
| 4307 | enforceTelephonyFeatureWithException(callingPackage, |
| 4308 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4309 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4310 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4311 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4312 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4313 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4314 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4315 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4316 | * Sets the voice activation state of a given subId. |
| 4317 | */ |
| 4318 | @Override |
| 4319 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4321 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4322 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4323 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4324 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4325 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | final Phone phone = getPhone(subId); |
| 4329 | if (phone != null) { |
| 4330 | phone.setVoiceActivationState(activationState); |
| 4331 | } else { |
| 4332 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4333 | } |
| 4334 | } finally { |
| 4335 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | /** |
| 4340 | * Sets the data activation state of a given subId. |
| 4341 | */ |
| 4342 | @Override |
| 4343 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4345 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4346 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4347 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4348 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4350 | final long identity = Binder.clearCallingIdentity(); |
| 4351 | try { |
| 4352 | final Phone phone = getPhone(subId); |
| 4353 | if (phone != null) { |
| 4354 | phone.setDataActivationState(activationState); |
| 4355 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4356 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4357 | } |
| 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * Returns the voice activation state of a given subId. |
| 4365 | */ |
| 4366 | @Override |
| 4367 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4368 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4369 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4370 | enforceTelephonyFeatureWithException(callingPackage, |
| 4371 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4372 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4373 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
| 4376 | if (phone != null) { |
| 4377 | return phone.getVoiceActivationState(); |
| 4378 | } else { |
| 4379 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4380 | } |
| 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | /** |
| 4387 | * Returns the data activation state of a given subId. |
| 4388 | */ |
| 4389 | @Override |
| 4390 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4391 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4393 | enforceTelephonyFeatureWithException(callingPackage, |
| 4394 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4395 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4396 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4397 | final long identity = Binder.clearCallingIdentity(); |
| 4398 | try { |
| 4399 | if (phone != null) { |
| 4400 | return phone.getDataActivationState(); |
| 4401 | } else { |
| 4402 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4403 | } |
| 4404 | } finally { |
| 4405 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4410 | * Returns the unread count of voicemails for a subId |
| 4411 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4412 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4413 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4414 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4415 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4416 | mApp, subId, callingPackage, callingFeatureId, |
| 4417 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4418 | return 0; |
| 4419 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4420 | final long identity = Binder.clearCallingIdentity(); |
| 4421 | try { |
| 4422 | final Phone phone = getPhone(subId); |
| 4423 | if (phone != null) { |
| 4424 | return phone.getVoiceMessageCount(); |
| 4425 | } else { |
| 4426 | return 0; |
| 4427 | } |
| 4428 | } finally { |
| 4429 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4431 | } |
| 4432 | |
| 4433 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4434 | * returns true, if the device is in a state where both voice and data |
| 4435 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4436 | */ |
| 4437 | @Override |
| 4438 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4439 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4440 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | final long identity = Binder.clearCallingIdentity(); |
| 4443 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4444 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4445 | } finally { |
| 4446 | Binder.restoreCallingIdentity(identity); |
| 4447 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4451 | * Send the dialer code if called from the current default dialer or the caller has |
| 4452 | * carrier privilege. |
| 4453 | * @param inputCode The dialer code to send |
| 4454 | */ |
| 4455 | @Override |
| 4456 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4457 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4458 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4459 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4460 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4461 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4462 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4463 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4464 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4465 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4466 | enforceTelephonyFeatureWithException(callingPackage, |
| 4467 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4469 | final long identity = Binder.clearCallingIdentity(); |
| 4470 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4471 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | } finally { |
| 4473 | Binder.restoreCallingIdentity(identity); |
| 4474 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4475 | } |
| 4476 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4477 | @Override |
| 4478 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4479 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4480 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4481 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4482 | |
| 4483 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4484 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4485 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4486 | final long identity = Binder.clearCallingIdentity(); |
| 4487 | try { |
| 4488 | if (!isActiveSubscription(subId)) { |
| 4489 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4490 | } |
| 4491 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4492 | } finally { |
| 4493 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4494 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4497 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4498 | public boolean isInEmergencySmsMode() { |
| 4499 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4500 | |
| 4501 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4502 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4503 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4507 | if (phone.isInEmergencySmsMode()) { |
| 4508 | return true; |
| 4509 | } |
| 4510 | } |
| 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(identity); |
| 4513 | } |
| 4514 | return false; |
| 4515 | } |
| 4516 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4517 | /** |
| 4518 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4519 | * @param subId The subscription to use to check the configuration. |
| 4520 | * @param c The callback that will be used to send the result. |
| 4521 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4522 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4523 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4524 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4525 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4526 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4527 | |
| 4528 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4529 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4530 | "IMS not available on device."); |
| 4531 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4532 | final long token = Binder.clearCallingIdentity(); |
| 4533 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4534 | int slotId = getSlotIndexOrException(subId); |
| 4535 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4536 | |
| 4537 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4538 | if (controller != null) { |
| 4539 | ImsManager imsManager = controller.getImsManager(subId); |
| 4540 | if (imsManager != null) { |
| 4541 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4542 | } else { |
| 4543 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4544 | } |
| 4545 | } else { |
| 4546 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4547 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4548 | } catch (ImsException e) { |
| 4549 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4550 | } finally { |
| 4551 | Binder.restoreCallingIdentity(token); |
| 4552 | } |
| 4553 | } |
| 4554 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4555 | /** |
| 4556 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4557 | * @param subId The subscription to use to check the configuration. |
| 4558 | * @param c The callback that will be used to send the result. |
| 4559 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4560 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4561 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4562 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4563 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4564 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4565 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4566 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4567 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4568 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4569 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4570 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4571 | if (controller != null) { |
| 4572 | ImsManager imsManager = controller.getImsManager(subId); |
| 4573 | if (imsManager != null) { |
| 4574 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4575 | } else { |
| 4576 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4577 | + "is inactive, ignoring unregister."); |
| 4578 | // If the ImsManager is not valid, just return, since the callback |
| 4579 | // will already have been removed internally. |
| 4580 | } |
| 4581 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(token); |
| 4584 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4587 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4588 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4589 | * @param subId The subscription to use to check the configuration. |
| 4590 | * @param c The callback that will be used to send the result. |
| 4591 | */ |
| 4592 | @Override |
| 4593 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4594 | throws RemoteException { |
| 4595 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4596 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4597 | |
| 4598 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4599 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4600 | "IMS not available on device."); |
| 4601 | } |
| 4602 | final long token = Binder.clearCallingIdentity(); |
| 4603 | try { |
| 4604 | int slotId = getSlotIndexOrException(subId); |
| 4605 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4606 | |
| 4607 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4608 | if (controller != null) { |
| 4609 | ImsManager imsManager = controller.getImsManager(subId); |
| 4610 | if (imsManager != null) { |
| 4611 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4612 | } else { |
| 4613 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4614 | } |
| 4615 | } else { |
| 4616 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4617 | } |
| 4618 | } catch (ImsException e) { |
| 4619 | throw new ServiceSpecificException(e.getCode()); |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(token); |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | /** |
| 4626 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4627 | * @param subId The subscription to use to check the configuration. |
| 4628 | * @param c The callback that will be used to send the result. |
| 4629 | */ |
| 4630 | @Override |
| 4631 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4632 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4633 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4634 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4635 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4636 | } |
| 4637 | final long token = Binder.clearCallingIdentity(); |
| 4638 | |
| 4639 | try { |
| 4640 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4641 | if (controller != null) { |
| 4642 | ImsManager imsManager = controller.getImsManager(subId); |
| 4643 | if (imsManager != null) { |
| 4644 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4645 | } else { |
| 4646 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4647 | + "is inactive, ignoring unregister."); |
| 4648 | // If the ImsManager is not valid, just return, since the callback |
| 4649 | // will already have been removed internally. |
| 4650 | } |
| 4651 | } |
| 4652 | } finally { |
| 4653 | Binder.restoreCallingIdentity(token); |
| 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4658 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4659 | */ |
| 4660 | @Override |
| 4661 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4662 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4663 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4664 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4665 | "IMS not available on device."); |
| 4666 | } |
| 4667 | final long token = Binder.clearCallingIdentity(); |
| 4668 | try { |
| 4669 | Phone phone = getPhone(subId); |
| 4670 | if (phone == null) { |
| 4671 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4672 | + subId + "'"); |
| 4673 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4674 | } |
| 4675 | phone.getImsRegistrationState(regState -> { |
| 4676 | try { |
| 4677 | consumer.accept((regState == null) |
| 4678 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4679 | } catch (RemoteException e) { |
| 4680 | // Ignore if the remote process is no longer available to call back. |
| 4681 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4682 | } |
| 4683 | }); |
| 4684 | } finally { |
| 4685 | Binder.restoreCallingIdentity(token); |
| 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | /** |
| 4690 | * Get the transport type for the IMS service registration state. |
| 4691 | */ |
| 4692 | @Override |
| 4693 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4694 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4695 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4696 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4697 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4698 | "IMS not available on device."); |
| 4699 | } |
| 4700 | final long token = Binder.clearCallingIdentity(); |
| 4701 | try { |
| 4702 | Phone phone = getPhone(subId); |
| 4703 | if (phone == null) { |
| 4704 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4705 | + subId + "'"); |
| 4706 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4707 | } |
| 4708 | phone.getImsRegistrationTech(regTech -> { |
| 4709 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4710 | int regTechConverted = (regTech == null) |
| 4711 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4712 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4713 | regTechConverted); |
| 4714 | try { |
| 4715 | consumer.accept(regTechConverted); |
| 4716 | } catch (RemoteException e) { |
| 4717 | // Ignore if the remote process is no longer available to call back. |
| 4718 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4719 | } |
| 4720 | }); |
| 4721 | } finally { |
| 4722 | Binder.restoreCallingIdentity(token); |
| 4723 | } |
| 4724 | } |
| 4725 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4726 | /** |
| 4727 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4728 | * @param subId The subscription to use to check the configuration. |
| 4729 | * @param c The callback that will be used to send the result. |
| 4730 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4731 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4732 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4733 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4734 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4735 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4736 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4737 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4738 | "IMS not available on device."); |
| 4739 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4740 | final long token = Binder.clearCallingIdentity(); |
| 4741 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4742 | int slotId = getSlotIndexOrException(subId); |
| 4743 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4744 | |
| 4745 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4746 | if (controller != null) { |
| 4747 | ImsManager imsManager = controller.getImsManager(subId); |
| 4748 | if (imsManager != null) { |
| 4749 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4750 | } else { |
| 4751 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4752 | } |
| 4753 | } else { |
| 4754 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4755 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4756 | } catch (ImsException e) { |
| 4757 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4758 | } finally { |
| 4759 | Binder.restoreCallingIdentity(token); |
| 4760 | } |
| 4761 | } |
| 4762 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4763 | /** |
| 4764 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4765 | * @param subId The subscription to use to check the configuration. |
| 4766 | * @param c The callback that will be used to send the result. |
| 4767 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4768 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4769 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
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, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4772 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4773 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4774 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4775 | |
| 4776 | final long token = Binder.clearCallingIdentity(); |
| 4777 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4778 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4779 | if (controller != null) { |
| 4780 | ImsManager imsManager = controller.getImsManager(subId); |
| 4781 | if (imsManager != null) { |
| 4782 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4783 | } else { |
| 4784 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4785 | + " is inactive, ignoring unregister."); |
| 4786 | // If the ImsManager is not valid, just return, since the callback |
| 4787 | // will already have been removed internally. |
| 4788 | } |
| 4789 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4790 | } finally { |
| 4791 | Binder.restoreCallingIdentity(token); |
| 4792 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4796 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4797 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4798 | |
| 4799 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4800 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4801 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4802 | final long token = Binder.clearCallingIdentity(); |
| 4803 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4804 | int slotId = getSlotIndexOrException(subId); |
| 4805 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4806 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4807 | } catch (com.android.ims.ImsException e) { |
| 4808 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4809 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4810 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4811 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4812 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4813 | } finally { |
| 4814 | Binder.restoreCallingIdentity(token); |
| 4815 | } |
| 4816 | } |
| 4817 | |
| 4818 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4819 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4820 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4821 | |
| 4822 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4823 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4824 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4825 | final long token = Binder.clearCallingIdentity(); |
| 4826 | try { |
| 4827 | Phone phone = getPhone(subId); |
| 4828 | if (phone == null) return false; |
| 4829 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4830 | } catch (com.android.ims.ImsException e) { |
| 4831 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4832 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4833 | } finally { |
| 4834 | Binder.restoreCallingIdentity(token); |
| 4835 | } |
| 4836 | } |
| 4837 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4838 | /** |
| 4839 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4840 | * subscription. |
| 4841 | * @param subId The subscription to use to check the configuration. |
| 4842 | * @param callback The callback that will be used to send the result. |
| 4843 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4844 | * @param transportType The transport type of the MmTelFeature capability. |
| 4845 | */ |
| 4846 | @Override |
| 4847 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4848 | int transportType) { |
| 4849 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4850 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4851 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4852 | "IMS not available on device."); |
| 4853 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4854 | final long token = Binder.clearCallingIdentity(); |
| 4855 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4856 | int slotId = getSlotIndex(subId); |
| 4857 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4858 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4859 | + subId + "'"); |
| 4860 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4861 | } |
| 4862 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4863 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4864 | transportType, aBoolean -> { |
| 4865 | try { |
| 4866 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4867 | } catch (RemoteException e) { |
| 4868 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4869 | + "running. Ignore"); |
| 4870 | } |
| 4871 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4872 | } catch (ImsException e) { |
| 4873 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4874 | } finally { |
| 4875 | Binder.restoreCallingIdentity(token); |
| 4876 | } |
| 4877 | } |
| 4878 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4879 | /** |
| 4880 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4881 | * @param subId The subscription to use to check the configuration. |
| 4882 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | @Override |
| 4884 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4885 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4886 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4887 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4888 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4889 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4890 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4891 | final long token = Binder.clearCallingIdentity(); |
| 4892 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4893 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4894 | // 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] | 4895 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4896 | } catch (ImsException e) { |
| 4897 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4898 | } finally { |
| 4899 | Binder.restoreCallingIdentity(token); |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4904 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4905 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4906 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4907 | |
| 4908 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4909 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4910 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4911 | final long identity = Binder.clearCallingIdentity(); |
| 4912 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4913 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4914 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4915 | // 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] | 4916 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4917 | } catch (ImsException e) { |
| 4918 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4919 | } finally { |
| 4920 | Binder.restoreCallingIdentity(identity); |
| 4921 | } |
| 4922 | } |
| 4923 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4924 | /** |
| 4925 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4926 | * @param subId The subscription to use to check the configuration. |
| 4927 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4928 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4929 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4930 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4931 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4932 | |
| 4933 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4934 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4935 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4936 | final long identity = Binder.clearCallingIdentity(); |
| 4937 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4938 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4939 | // 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] | 4940 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4941 | } catch (ImsException e) { |
| 4942 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4943 | } finally { |
| 4944 | Binder.restoreCallingIdentity(identity); |
| 4945 | } |
| 4946 | } |
| 4947 | |
| 4948 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4949 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4951 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4952 | |
| 4953 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4954 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4955 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4956 | final long identity = Binder.clearCallingIdentity(); |
| 4957 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4958 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4959 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4960 | // 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] | 4961 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4962 | } catch (ImsException e) { |
| 4963 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4964 | } finally { |
| 4965 | Binder.restoreCallingIdentity(identity); |
| 4966 | } |
| 4967 | } |
| 4968 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4969 | /** |
| 4970 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4971 | * @param subId The subscription to use to check the configuration. |
| 4972 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4973 | @Override |
| 4974 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4975 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4976 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4977 | |
| 4978 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4979 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 4980 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4981 | final long identity = Binder.clearCallingIdentity(); |
| 4982 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4983 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4984 | // 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] | 4985 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4986 | } catch (ImsException e) { |
| 4987 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4988 | } finally { |
| 4989 | Binder.restoreCallingIdentity(identity); |
| 4990 | } |
| 4991 | } |
| 4992 | |
| 4993 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4994 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4995 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4996 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4997 | |
| 4998 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4999 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5000 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5001 | final long identity = Binder.clearCallingIdentity(); |
| 5002 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5003 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5004 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5005 | // 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] | 5006 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5007 | } catch (ImsException e) { |
| 5008 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5009 | } finally { |
| 5010 | Binder.restoreCallingIdentity(identity); |
| 5011 | } |
| 5012 | } |
| 5013 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5014 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5015 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5016 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5017 | * @param subId The subscription to use to check the configuration. |
| 5018 | */ |
| 5019 | @Override |
| 5020 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5021 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5022 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5023 | |
| 5024 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5025 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5026 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5027 | final long identity = Binder.clearCallingIdentity(); |
| 5028 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5029 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5030 | // 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] | 5031 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5032 | } catch (ImsException e) { |
| 5033 | throw new ServiceSpecificException(e.getCode()); |
| 5034 | } finally { |
| 5035 | Binder.restoreCallingIdentity(identity); |
| 5036 | } |
| 5037 | } |
| 5038 | |
| 5039 | /** |
| 5040 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5041 | * Requires MODIFY_PHONE_STATE permission. |
| 5042 | * @param subId The subscription to use to check the configuration. |
| 5043 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5044 | * false otherwise |
| 5045 | */ |
| 5046 | @Override |
| 5047 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5049 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5050 | |
| 5051 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5052 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5053 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5056 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5057 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5058 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5059 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5060 | } catch (ImsException e) { |
| 5061 | throw new ServiceSpecificException(e.getCode()); |
| 5062 | } finally { |
| 5063 | Binder.restoreCallingIdentity(identity); |
| 5064 | } |
| 5065 | } |
| 5066 | |
| 5067 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5068 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5069 | * @param subId The subscription to use to check the configuration. |
| 5070 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5071 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5072 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5073 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5074 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5075 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5076 | |
| 5077 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5078 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5079 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5080 | final long identity = Binder.clearCallingIdentity(); |
| 5081 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5082 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5083 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5084 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5085 | } catch (ImsException e) { |
| 5086 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5093 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5095 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5096 | |
| 5097 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5098 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5099 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5100 | final long identity = Binder.clearCallingIdentity(); |
| 5101 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5102 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5103 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5104 | // 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] | 5105 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5106 | } catch (ImsException e) { |
| 5107 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5108 | } finally { |
| 5109 | Binder.restoreCallingIdentity(identity); |
| 5110 | } |
| 5111 | } |
| 5112 | |
| 5113 | @Override |
| 5114 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5115 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5116 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5117 | |
| 5118 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5119 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5120 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5121 | final long identity = Binder.clearCallingIdentity(); |
| 5122 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5123 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5124 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5125 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5126 | } catch (ImsException e) { |
| 5127 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5128 | } finally { |
| 5129 | Binder.restoreCallingIdentity(identity); |
| 5130 | } |
| 5131 | } |
| 5132 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5133 | /** |
| 5134 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5135 | * @param subId The subscription to use to check the configuration. |
| 5136 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5137 | @Override |
| 5138 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5139 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5140 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5141 | |
| 5142 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5143 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5144 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5145 | final long identity = Binder.clearCallingIdentity(); |
| 5146 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5147 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5148 | // 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] | 5149 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5150 | } catch (ImsException e) { |
| 5151 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5152 | } finally { |
| 5153 | Binder.restoreCallingIdentity(identity); |
| 5154 | } |
| 5155 | } |
| 5156 | |
| 5157 | @Override |
| 5158 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5160 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5161 | |
| 5162 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5163 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5164 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5165 | final long identity = Binder.clearCallingIdentity(); |
| 5166 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5167 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5168 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5169 | // 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] | 5170 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5171 | } catch (ImsException e) { |
| 5172 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5173 | } finally { |
| 5174 | Binder.restoreCallingIdentity(identity); |
| 5175 | } |
| 5176 | } |
| 5177 | |
| 5178 | @Override |
| 5179 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5180 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5181 | |
| 5182 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5183 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5184 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5187 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5188 | // 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] | 5189 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5190 | } catch (ImsException e) { |
| 5191 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | @Override |
| 5198 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5199 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5200 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5201 | |
| 5202 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5203 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5204 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5207 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5208 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5209 | // 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] | 5210 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5211 | } catch (ImsException e) { |
| 5212 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5213 | } finally { |
| 5214 | Binder.restoreCallingIdentity(identity); |
| 5215 | } |
| 5216 | } |
| 5217 | |
| 5218 | @Override |
| 5219 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5221 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5222 | |
| 5223 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5224 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5225 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5226 | final long identity = Binder.clearCallingIdentity(); |
| 5227 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5228 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5229 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5230 | // 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] | 5231 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5232 | } catch (ImsException e) { |
| 5233 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5234 | } finally { |
| 5235 | Binder.restoreCallingIdentity(identity); |
| 5236 | } |
| 5237 | } |
| 5238 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5239 | /** |
| 5240 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5241 | * @param subId The subscription to use to check the configuration. |
| 5242 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5243 | @Override |
| 5244 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5245 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5246 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5247 | |
| 5248 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5249 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5250 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5253 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5254 | // 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] | 5255 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5256 | } catch (ImsException e) { |
| 5257 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
| 5260 | } |
| 5261 | } |
| 5262 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5263 | @Override |
| 5264 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5265 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5266 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5267 | final long identity = Binder.clearCallingIdentity(); |
| 5268 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5269 | if (!isImsAvailableOnDevice()) { |
| 5270 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5271 | "IMS not available on device."); |
| 5272 | } |
| 5273 | int slotId = getSlotIndexOrException(subId); |
| 5274 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5275 | |
| 5276 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5277 | if (controller != null) { |
| 5278 | ImsManager imsManager = controller.getImsManager(subId); |
| 5279 | if (imsManager != null) { |
| 5280 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5281 | } else { |
| 5282 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5283 | } |
| 5284 | } else { |
| 5285 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5286 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5287 | } catch (ImsException e) { |
| 5288 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5289 | } finally { |
| 5290 | Binder.restoreCallingIdentity(identity); |
| 5291 | } |
| 5292 | } |
| 5293 | |
| 5294 | @Override |
| 5295 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5296 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5297 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5298 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5299 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5300 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5301 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5302 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5303 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5304 | if (controller != null) { |
| 5305 | ImsManager imsManager = controller.getImsManager(subId); |
| 5306 | if (imsManager != null) { |
| 5307 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5308 | } else { |
| 5309 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5310 | + " is inactive, ignoring unregister."); |
| 5311 | // If the ImsManager is not valid, just return, since the callback will already |
| 5312 | // have been removed internally. |
| 5313 | } |
| 5314 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5315 | } finally { |
| 5316 | Binder.restoreCallingIdentity(identity); |
| 5317 | } |
| 5318 | } |
| 5319 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5320 | @Override |
| 5321 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5322 | IFeatureProvisioningCallback callback) { |
| 5323 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5324 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5325 | |
| 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5328 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5329 | } |
| 5330 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5331 | try { |
| 5332 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5333 | if (controller == null) { |
| 5334 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5335 | "Device does not support IMS"); |
| 5336 | } |
| 5337 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5338 | } finally { |
| 5339 | Binder.restoreCallingIdentity(identity); |
| 5340 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | @Override |
| 5344 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5345 | IFeatureProvisioningCallback callback) { |
| 5346 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5347 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5348 | |
| 5349 | final long identity = Binder.clearCallingIdentity(); |
| 5350 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5351 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5352 | } |
| 5353 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5354 | try { |
| 5355 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5356 | if (controller == null) { |
| 5357 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5358 | return; |
| 5359 | } |
| 5360 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5361 | } finally { |
| 5362 | Binder.restoreCallingIdentity(identity); |
| 5363 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5364 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5365 | |
| 5366 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5367 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5368 | message); |
| 5369 | } |
| 5370 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5371 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5372 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5373 | boolean isProvisioned) { |
| 5374 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5375 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5376 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5377 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5378 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5381 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5382 | if (controller == null) { |
| 5383 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5384 | return; |
| 5385 | } |
| 5386 | controller.setRcsProvisioningStatusForCapability( |
| 5387 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5388 | } finally { |
| 5389 | Binder.restoreCallingIdentity(identity); |
| 5390 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | |
| 5394 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5395 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5396 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5397 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5398 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5399 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5400 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5401 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5402 | final long identity = Binder.clearCallingIdentity(); |
| 5403 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5404 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5405 | if (controller == null) { |
| 5406 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5407 | |
| 5408 | // device does not support IMS, this method will return true always. |
| 5409 | return true; |
| 5410 | } |
| 5411 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5412 | } finally { |
| 5413 | Binder.restoreCallingIdentity(identity); |
| 5414 | } |
| 5415 | } |
| 5416 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5417 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5418 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5419 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5420 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5421 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5422 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5423 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5424 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5425 | final long identity = Binder.clearCallingIdentity(); |
| 5426 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5427 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5428 | if (controller == null) { |
| 5429 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5430 | return; |
| 5431 | } |
| 5432 | controller.setImsProvisioningStatusForCapability( |
| 5433 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5434 | } finally { |
| 5435 | Binder.restoreCallingIdentity(identity); |
| 5436 | } |
| 5437 | } |
| 5438 | |
| 5439 | @Override |
| 5440 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5441 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5442 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5443 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5444 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5445 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5446 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5447 | final long identity = Binder.clearCallingIdentity(); |
| 5448 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5449 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5450 | if (controller == null) { |
| 5451 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5452 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5453 | // device does not support IMS, this method will return true always. |
| 5454 | return true; |
| 5455 | } |
| 5456 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5457 | } finally { |
| 5458 | Binder.restoreCallingIdentity(identity); |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5463 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5464 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5465 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5466 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5467 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5468 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5469 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5470 | final long identity = Binder.clearCallingIdentity(); |
| 5471 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5472 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5473 | if (controller == null) { |
| 5474 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5475 | |
| 5476 | // device does not support IMS, this method will return false |
| 5477 | return false; |
| 5478 | } |
| 5479 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5482 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5486 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5487 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5488 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5489 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5490 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5491 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5492 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5493 | final long identity = Binder.clearCallingIdentity(); |
| 5494 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5495 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5496 | if (controller == null) { |
| 5497 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5498 | |
| 5499 | // device does not support IMS, this method will return false |
| 5500 | return false; |
| 5501 | } |
| 5502 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5503 | } finally { |
| 5504 | Binder.restoreCallingIdentity(identity); |
| 5505 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5506 | } |
| 5507 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5508 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5509 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5510 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5511 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5512 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5513 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5514 | mApp, subId, "getImsProvisioningInt"); |
| 5515 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5516 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5517 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5518 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5519 | final long identity = Binder.clearCallingIdentity(); |
| 5520 | try { |
| 5521 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5522 | int slotId = getSlotIndex(subId); |
| 5523 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5524 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5525 | + subId + "' for key:" + key); |
| 5526 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5527 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5528 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5529 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5530 | if (controller == null) { |
| 5531 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5532 | |
| 5533 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5534 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5535 | } |
| 5536 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5537 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5538 | return retVal; |
| 5539 | } |
| 5540 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5541 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5542 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5543 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5544 | + subId + "' for key:" + key); |
| 5545 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5546 | } finally { |
| 5547 | Binder.restoreCallingIdentity(identity); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | @Override |
| 5552 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5553 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5554 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5555 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5556 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5557 | mApp, subId, "getImsProvisioningString"); |
| 5558 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5559 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5560 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5561 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5565 | int slotId = getSlotIndex(subId); |
| 5566 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5567 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5568 | + subId + "' for key:" + key); |
| 5569 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5570 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5571 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5572 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5573 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5574 | + subId + "' for key:" + key); |
| 5575 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5576 | } finally { |
| 5577 | Binder.restoreCallingIdentity(identity); |
| 5578 | } |
| 5579 | } |
| 5580 | |
| 5581 | @Override |
| 5582 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5583 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5584 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5585 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5587 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5588 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5589 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5590 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5591 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
| 5594 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5595 | int slotId = getSlotIndex(subId); |
| 5596 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5597 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5598 | + subId + "' for key:" + key); |
| 5599 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5600 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5601 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5602 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5603 | if (controller == null) { |
| 5604 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5605 | |
| 5606 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5607 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5608 | } |
| 5609 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5610 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5611 | return retVal; |
| 5612 | } |
| 5613 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5614 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5615 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5616 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5617 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5618 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5619 | } finally { |
| 5620 | Binder.restoreCallingIdentity(identity); |
| 5621 | } |
| 5622 | } |
| 5623 | |
| 5624 | @Override |
| 5625 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5626 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5627 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5628 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5630 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5631 | |
| 5632 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5633 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5634 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5635 | final long identity = Binder.clearCallingIdentity(); |
| 5636 | try { |
| 5637 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5638 | int slotId = getSlotIndex(subId); |
| 5639 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5640 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5641 | + subId + "' for key:" + key); |
| 5642 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5643 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5644 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5645 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5646 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5647 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5648 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5649 | } finally { |
| 5650 | Binder.restoreCallingIdentity(identity); |
| 5651 | } |
| 5652 | } |
| 5653 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5654 | /** |
| 5655 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5656 | * for the given slot ID or no ImsResolver instance has been created. |
| 5657 | * @param slotId The slot ID that the IMS service is created for. |
| 5658 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5659 | */ |
| 5660 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5661 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5662 | ImsFeature.FEATURE_MMTEL)) { |
| 5663 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5664 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5665 | } |
| 5666 | } |
| 5667 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5668 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5669 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5670 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5671 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5672 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5673 | } |
| 5674 | return slotId; |
| 5675 | } |
| 5676 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5677 | private int getSlotIndex(int subId) { |
| 5678 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5679 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5680 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5681 | } |
| 5682 | return slotId; |
| 5683 | } |
| 5684 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5685 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5686 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5687 | */ |
| 5688 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5689 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5690 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5691 | try { |
| 5692 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5693 | } catch (SecurityException se) { |
| 5694 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5695 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5696 | + Binder.getCallingUid()); |
| 5697 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5698 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5699 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5700 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5701 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5702 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5703 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5704 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5705 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5706 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5707 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5708 | enforceTelephonyFeatureWithException(callingPackage, |
| 5709 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5710 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5711 | final long identity = Binder.clearCallingIdentity(); |
| 5712 | try { |
| 5713 | final Phone phone = getPhone(subId); |
| 5714 | if (phone != null) { |
| 5715 | return phone.getServiceState().getDataNetworkType(); |
| 5716 | } else { |
| 5717 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5718 | } |
| 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5721 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | /** |
| 5725 | * Returns the data network type |
| 5726 | */ |
| 5727 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5728 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5729 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5730 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | /** |
| 5734 | * Returns the data network type for a subId |
| 5735 | */ |
| 5736 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5737 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5738 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5739 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5740 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5741 | mApp, functionName)) { |
| 5742 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5743 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5744 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5745 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5746 | } |
| 5747 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5748 | enforceTelephonyFeatureWithException(callingPackage, |
| 5749 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | final long identity = Binder.clearCallingIdentity(); |
| 5752 | try { |
| 5753 | final Phone phone = getPhone(subId); |
| 5754 | if (phone != null) { |
| 5755 | return phone.getServiceState().getDataNetworkType(); |
| 5756 | } else { |
| 5757 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5758 | } |
| 5759 | } finally { |
| 5760 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5761 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5765 | * Returns the Voice network type for a subId |
| 5766 | */ |
| 5767 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5768 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5769 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5770 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5771 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5772 | mApp, functionName)) { |
| 5773 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5774 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5775 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5776 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5779 | enforceTelephonyFeatureWithException(callingPackage, |
| 5780 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5781 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5782 | final long identity = Binder.clearCallingIdentity(); |
| 5783 | try { |
| 5784 | final Phone phone = getPhone(subId); |
| 5785 | if (phone != null) { |
| 5786 | return phone.getServiceState().getVoiceNetworkType(); |
| 5787 | } else { |
| 5788 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5789 | } |
| 5790 | } finally { |
| 5791 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5792 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | /** |
| 5796 | * @return true if a ICC card is present |
| 5797 | */ |
| 5798 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5799 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5800 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5801 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5805 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5806 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5807 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5808 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5809 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5810 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | final long identity = Binder.clearCallingIdentity(); |
| 5813 | try { |
| 5814 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5815 | if (phone != null) { |
| 5816 | return phone.getIccCard().hasIccCard(); |
| 5817 | } else { |
| 5818 | return false; |
| 5819 | } |
| 5820 | } finally { |
| 5821 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5822 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | /** |
| 5826 | * Return if the current radio is LTE on CDMA. This |
| 5827 | * is a tri-state return value as for a period of time |
| 5828 | * the mode may be unknown. |
| 5829 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5830 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5831 | * @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] | 5832 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5833 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5834 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5835 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5836 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5837 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5838 | } |
| 5839 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5840 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5841 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5842 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5843 | try { |
| 5844 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5845 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5846 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5847 | } |
| 5848 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5849 | enforceTelephonyFeatureWithException(callingPackage, |
| 5850 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5851 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5852 | final long identity = Binder.clearCallingIdentity(); |
| 5853 | try { |
| 5854 | final Phone phone = getPhone(subId); |
| 5855 | if (phone == null) { |
| 5856 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5857 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5858 | return TelephonyProperties.lte_on_cdma_device() |
| 5859 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5860 | } |
| 5861 | } finally { |
| 5862 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5863 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5866 | /** |
| 5867 | * {@hide} |
| 5868 | * Returns Default subId, 0 in the case of single standby. |
| 5869 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5870 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5871 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5874 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5875 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5876 | } |
| 5877 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5878 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5879 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5880 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5881 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5882 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5883 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5884 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5885 | } |
| 5886 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5887 | /** |
| 5888 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5889 | */ |
| 5890 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5891 | final long identity = Binder.clearCallingIdentity(); |
| 5892 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5893 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5895 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5896 | } finally { |
| 5897 | Binder.restoreCallingIdentity(identity); |
| 5898 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5899 | } |
| 5900 | |
| 5901 | /** |
| 5902 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5903 | */ |
| 5904 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5905 | final long identity = Binder.clearCallingIdentity(); |
| 5906 | try { |
| 5907 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5908 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5909 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5910 | } finally { |
| 5911 | Binder.restoreCallingIdentity(identity); |
| 5912 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5913 | } |
| 5914 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5915 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5916 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5917 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5918 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5919 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5920 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5921 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5922 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5923 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5924 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5925 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5926 | } |
| 5927 | return PhoneFactory.getPhone(phoneId); |
| 5928 | } |
| 5929 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5930 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5931 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5932 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5933 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5934 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5935 | /*message=*/ "iccOpenLogicalChannel"); |
| 5936 | |
| 5937 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5938 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5939 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5940 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5941 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5942 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5943 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5944 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5945 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5946 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5947 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5948 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5949 | Phone phone; |
| 5950 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5952 | mApp, request.subId, message); |
| 5953 | phone = getPhoneFromSubId(request.subId); |
| 5954 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5955 | enforceModifyPermission(); |
| 5956 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5957 | } else { |
| 5958 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5959 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5960 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5964 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5965 | final long identity = Binder.clearCallingIdentity(); |
| 5966 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5967 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5969 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5970 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5971 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5972 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5973 | loge("The calling package is not allowed to access ISD-R."); |
| 5974 | throw new SecurityException( |
| 5975 | "The calling package is not allowed to access ISD-R."); |
| 5976 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5977 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5979 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5980 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5981 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | return response; |
| 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
| 5985 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5989 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5990 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5991 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 5992 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5993 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5994 | /*message=*/"iccCloseLogicalChannel"); |
| 5995 | |
| 5996 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5997 | |
| 5998 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5999 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6000 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6001 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6002 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6003 | // before this feature is enabled, this API should only return false if |
| 6004 | // the operation fails instead of throwing runtime exception for |
| 6005 | // backward-compatibility. |
| 6006 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6007 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | final long identity = Binder.clearCallingIdentity(); |
| 6009 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6010 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6011 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6013 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6014 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6015 | Boolean success = false; |
| 6016 | if (result instanceof RuntimeException) { |
| 6017 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6018 | if (shouldThrowExceptionOnFailure) { |
| 6019 | throw (RuntimeException) result; |
| 6020 | } else { |
| 6021 | return false; |
| 6022 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6023 | } else if (result instanceof Boolean) { |
| 6024 | success = (Boolean) result; |
| 6025 | } else { |
| 6026 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6027 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6028 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6029 | return success; |
| 6030 | } finally { |
| 6031 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6032 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
| 6035 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6036 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6037 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6039 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6040 | |
| 6041 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6042 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6043 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6044 | if (DBG) { |
| 6045 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6046 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6047 | + p3 + " data=" + data); |
| 6048 | } |
| 6049 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6050 | command, p1, p2, p3, data); |
| 6051 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6052 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6053 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6054 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6055 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6056 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6057 | |
| 6058 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6059 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6060 | "iccTransmitApduLogicalChannelBySlot"); |
| 6061 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6062 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6063 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6064 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6065 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6066 | } |
| 6067 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6068 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6069 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6073 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6074 | final long identity = Binder.clearCallingIdentity(); |
| 6075 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6076 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6077 | return ""; |
| 6078 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6079 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6080 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6081 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6082 | null /* workSource */); |
| 6083 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6084 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6085 | // Append the returned status code to the end of the response payload. |
| 6086 | String s = Integer.toHexString( |
| 6087 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6088 | if (response.payload != null) { |
| 6089 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6090 | } |
| 6091 | return s; |
| 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6094 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6095 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6096 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6097 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6098 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6099 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6100 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6101 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6102 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6103 | |
| 6104 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6105 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6106 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6107 | if (DBG) { |
| 6108 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6109 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6110 | } |
| 6111 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6112 | cla, command, p1, p2, p3, data); |
| 6113 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6114 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6115 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6116 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6117 | 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] | 6118 | enforceModifyPermission(); |
| 6119 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6120 | |
| 6121 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6122 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6123 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6124 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6125 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6126 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6127 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6131 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6132 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6136 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6137 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6138 | final long identity = Binder.clearCallingIdentity(); |
| 6139 | try { |
| 6140 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6141 | && TextUtils.equals(ISDR_AID, data)) { |
| 6142 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6143 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6144 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | if (bestComponent == null |
| 6146 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6147 | loge("The calling package is not allowed to select ISD-R."); |
| 6148 | throw new SecurityException( |
| 6149 | "The calling package is not allowed to select ISD-R."); |
| 6150 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6151 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6152 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6153 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6154 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6155 | null /* workSource */); |
| 6156 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6157 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | // Append the returned status code to the end of the response payload. |
| 6159 | String s = Integer.toHexString( |
| 6160 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6161 | if (response.payload != null) { |
| 6162 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6163 | } |
| 6164 | return s; |
| 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6167 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6171 | 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] | 6172 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6174 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6175 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6176 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6177 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6178 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6179 | final long identity = Binder.clearCallingIdentity(); |
| 6180 | try { |
| 6181 | if (DBG) { |
| 6182 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6183 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6184 | } |
| 6185 | |
| 6186 | IccIoResult response = |
| 6187 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6188 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6189 | subId); |
| 6190 | |
| 6191 | if (DBG) { |
| 6192 | log("Exchange SIM_IO [R]" + response); |
| 6193 | } |
| 6194 | |
| 6195 | byte[] result = null; |
| 6196 | int length = 2; |
| 6197 | if (response.payload != null) { |
| 6198 | length = 2 + response.payload.length; |
| 6199 | result = new byte[length]; |
| 6200 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6201 | } else { |
| 6202 | result = new byte[length]; |
| 6203 | } |
| 6204 | |
| 6205 | result[length - 1] = (byte) response.sw2; |
| 6206 | result[length - 2] = (byte) response.sw1; |
| 6207 | return result; |
| 6208 | } finally { |
| 6209 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6210 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6211 | } |
| 6212 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6213 | /** |
| 6214 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6215 | * on a particular subscription |
| 6216 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6217 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6218 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6219 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6220 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6221 | return null; |
| 6222 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6223 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6224 | enforceTelephonyFeatureWithException(callingPackage, |
| 6225 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6226 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6227 | final long identity = Binder.clearCallingIdentity(); |
| 6228 | try { |
| 6229 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6230 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6231 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6232 | return null; |
| 6233 | } |
| 6234 | Object response = sendRequest( |
| 6235 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6236 | if (response instanceof String[]) { |
| 6237 | return (String[]) response; |
| 6238 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6239 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6240 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6241 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6244 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6245 | } |
| 6246 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6247 | /** |
| 6248 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6249 | * subscription. |
| 6250 | * |
| 6251 | * @param subId the id of the subscription. |
| 6252 | * @param appType the uicc app type, must be USIM or SIM. |
| 6253 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6254 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6255 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6256 | * @return number of fplmns that is successfully written to the SIM. |
| 6257 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6258 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6259 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6260 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6261 | mApp, subId, "setForbiddenPlmns"); |
| 6262 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6263 | enforceTelephonyFeatureWithException(callingPackage, |
| 6264 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6265 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6266 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6267 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6268 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6269 | } |
| 6270 | if (fplmns == null) { |
| 6271 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6272 | } |
| 6273 | for (String fplmn : fplmns) { |
| 6274 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6275 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6276 | } |
| 6277 | } |
| 6278 | final long identity = Binder.clearCallingIdentity(); |
| 6279 | try { |
| 6280 | Object response = sendRequest( |
| 6281 | CMD_SET_FORBIDDEN_PLMNS, |
| 6282 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6283 | subId); |
| 6284 | return (int) response; |
| 6285 | } finally { |
| 6286 | Binder.restoreCallingIdentity(identity); |
| 6287 | } |
| 6288 | } |
| 6289 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6290 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6291 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6293 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6294 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6295 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6296 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | final long identity = Binder.clearCallingIdentity(); |
| 6299 | try { |
| 6300 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6301 | if (response.payload == null) { |
| 6302 | return ""; |
| 6303 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6304 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6305 | // Append the returned status code to the end of the response payload. |
| 6306 | String s = Integer.toHexString( |
| 6307 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6308 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6309 | return s; |
| 6310 | } finally { |
| 6311 | Binder.restoreCallingIdentity(identity); |
| 6312 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6313 | } |
| 6314 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6315 | /** |
| 6316 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6317 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6318 | * |
| 6319 | * @param itemID the ID of the item to read |
| 6320 | * @return the NV item as a String, or null on error. |
| 6321 | */ |
| 6322 | @Override |
| 6323 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6324 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6326 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6327 | |
| 6328 | final long identity = Binder.clearCallingIdentity(); |
| 6329 | try { |
| 6330 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6331 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6332 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6333 | return value; |
| 6334 | } finally { |
| 6335 | Binder.restoreCallingIdentity(identity); |
| 6336 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6337 | } |
| 6338 | |
| 6339 | /** |
| 6340 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6341 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6342 | * |
| 6343 | * @param itemID the ID of the item to read |
| 6344 | * @param itemValue the value to write, as a String |
| 6345 | * @return true on success; false on any failure |
| 6346 | */ |
| 6347 | @Override |
| 6348 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6349 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6351 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6352 | |
| 6353 | final long identity = Binder.clearCallingIdentity(); |
| 6354 | try { |
| 6355 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6356 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6357 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6358 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6359 | return success; |
| 6360 | } finally { |
| 6361 | Binder.restoreCallingIdentity(identity); |
| 6362 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | /** |
| 6366 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6367 | * Used for device configuration by some CDMA operators. |
| 6368 | * |
| 6369 | * @param preferredRoamingList byte array containing the new PRL |
| 6370 | * @return true on success; false on any failure |
| 6371 | */ |
| 6372 | @Override |
| 6373 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6375 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6376 | |
| 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
| 6379 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6380 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6381 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6382 | return success; |
| 6383 | } finally { |
| 6384 | Binder.restoreCallingIdentity(identity); |
| 6385 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6386 | } |
| 6387 | |
| 6388 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6389 | * 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] | 6390 | * Used for device configuration by some CDMA operators. |
| 6391 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6392 | * @param slotIndex - device slot. |
| 6393 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6394 | * @return true on success; false on any failure |
| 6395 | */ |
| 6396 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6397 | public boolean resetModemConfig(int slotIndex) { |
| 6398 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6399 | if (phone != null) { |
| 6400 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6401 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6402 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6403 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6404 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6405 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6406 | final long identity = Binder.clearCallingIdentity(); |
| 6407 | try { |
| 6408 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6409 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6410 | return success; |
| 6411 | } finally { |
| 6412 | Binder.restoreCallingIdentity(identity); |
| 6413 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6415 | return false; |
| 6416 | } |
| 6417 | |
| 6418 | /** |
| 6419 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6420 | * |
| 6421 | * @param slotIndex - device slot. |
| 6422 | * |
| 6423 | * @return true on success; false on any failure |
| 6424 | */ |
| 6425 | @Override |
| 6426 | public boolean rebootModem(int slotIndex) { |
| 6427 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6428 | if (phone != null) { |
| 6429 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6430 | mApp, phone.getSubId(), "rebootModem"); |
| 6431 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6432 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6433 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6434 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6435 | final long identity = Binder.clearCallingIdentity(); |
| 6436 | try { |
| 6437 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6438 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6439 | return success; |
| 6440 | } finally { |
| 6441 | Binder.restoreCallingIdentity(identity); |
| 6442 | } |
| 6443 | } |
| 6444 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6445 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6446 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6447 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6448 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6449 | * {@link #disableIms(int)}. |
| 6450 | * @param slotIndex device slot. |
| 6451 | */ |
| 6452 | public void resetIms(int slotIndex) { |
| 6453 | enforceModifyPermission(); |
| 6454 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6455 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6456 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6457 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6458 | final long identity = Binder.clearCallingIdentity(); |
| 6459 | try { |
| 6460 | if (mImsResolver == null) { |
| 6461 | // may happen if the does not support IMS. |
| 6462 | return; |
| 6463 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6464 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6465 | } finally { |
| 6466 | Binder.restoreCallingIdentity(identity); |
| 6467 | } |
| 6468 | } |
| 6469 | |
| 6470 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6471 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6472 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6473 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6474 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6475 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6476 | |
| 6477 | final long identity = Binder.clearCallingIdentity(); |
| 6478 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6479 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6480 | // may happen if the device does not support IMS. |
| 6481 | return; |
| 6482 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6483 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6484 | } finally { |
| 6485 | Binder.restoreCallingIdentity(identity); |
| 6486 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6490 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6491 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6492 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6493 | public void disableIms(int slotId) { |
| 6494 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6495 | |
| 6496 | final long identity = Binder.clearCallingIdentity(); |
| 6497 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6498 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6499 | // may happen if the device does not support IMS. |
| 6500 | return; |
| 6501 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6502 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6503 | } finally { |
| 6504 | Binder.restoreCallingIdentity(identity); |
| 6505 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6506 | } |
| 6507 | |
| 6508 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6509 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6510 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6511 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6512 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6513 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6514 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6515 | |
| 6516 | final long identity = Binder.clearCallingIdentity(); |
| 6517 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6518 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6519 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6520 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6521 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6522 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6523 | } finally { |
| 6524 | Binder.restoreCallingIdentity(identity); |
| 6525 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6526 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6527 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6528 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6529 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6530 | @Override |
| 6531 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6532 | enforceModifyPermission(); |
| 6533 | |
| 6534 | final long identity = Binder.clearCallingIdentity(); |
| 6535 | try { |
| 6536 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6537 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6538 | } finally { |
| 6539 | Binder.restoreCallingIdentity(identity); |
| 6540 | } |
| 6541 | } |
| 6542 | |
| 6543 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6544 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6545 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6546 | */ |
| 6547 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6548 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | |
| 6550 | final long identity = Binder.clearCallingIdentity(); |
| 6551 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6552 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6553 | // may happen if the device does not support IMS. |
| 6554 | return null; |
| 6555 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6556 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | } finally { |
| 6558 | Binder.restoreCallingIdentity(identity); |
| 6559 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6560 | } |
| 6561 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6562 | /** |
| 6563 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6564 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6565 | */ |
| 6566 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6567 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6568 | |
| 6569 | final long identity = Binder.clearCallingIdentity(); |
| 6570 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6571 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6572 | // may happen if the device does not support IMS. |
| 6573 | return null; |
| 6574 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6575 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6576 | } finally { |
| 6577 | Binder.restoreCallingIdentity(identity); |
| 6578 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6579 | } |
| 6580 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6581 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6582 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6583 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6584 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6585 | * @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] | 6586 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6587 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6588 | * @param packageName The name of the package that the current configuration will be replaced |
| 6589 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6590 | * @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] | 6591 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6592 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6593 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6594 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6596 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6597 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6598 | final long identity = Binder.clearCallingIdentity(); |
| 6599 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6600 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6601 | // may happen if the device does not support IMS. |
| 6602 | return false; |
| 6603 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6604 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6605 | for (int featureType : featureTypes) { |
| 6606 | featureConfig.put(featureType, packageName); |
| 6607 | } |
| 6608 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6609 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
| 6612 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6616 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6617 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6618 | * |
| 6619 | * This should only be used for testing. |
| 6620 | * |
| 6621 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6622 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6623 | */ |
| 6624 | @Override |
| 6625 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6626 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6627 | "clearCarrierImsServiceOverride"); |
| 6628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6629 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6630 | |
| 6631 | final long identity = Binder.clearCallingIdentity(); |
| 6632 | try { |
| 6633 | if (mImsResolver == null) { |
| 6634 | // may happen if the device does not support IMS. |
| 6635 | return false; |
| 6636 | } |
| 6637 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6638 | } finally { |
| 6639 | Binder.restoreCallingIdentity(identity); |
| 6640 | } |
| 6641 | } |
| 6642 | |
| 6643 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6644 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6645 | * |
| 6646 | * @param slotId The slot that the ImsService is associated with. |
| 6647 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6648 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6649 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6650 | * @return the package name of the ImsService configuration. |
| 6651 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6652 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6653 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6654 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6655 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6656 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6660 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6661 | // may happen if the device does not support IMS. |
| 6662 | return ""; |
| 6663 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6664 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6665 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6666 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6667 | } finally { |
| 6668 | Binder.restoreCallingIdentity(identity); |
| 6669 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6670 | } |
| 6671 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6672 | /** |
| 6673 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6674 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6675 | * @param callback A callback with an integer containing the |
| 6676 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6677 | */ |
| 6678 | @Override |
| 6679 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6680 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6681 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6682 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6683 | "IMS not available on device."); |
| 6684 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6685 | final long token = Binder.clearCallingIdentity(); |
| 6686 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6687 | int slotId = getSlotIndex(subId); |
| 6688 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6689 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6690 | + subId + "'"); |
| 6691 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6692 | } |
| 6693 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6694 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6695 | try { |
| 6696 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6697 | } catch (RemoteException e) { |
| 6698 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6699 | + "Ignore"); |
| 6700 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6701 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6702 | } catch (ImsException e) { |
| 6703 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6704 | } finally { |
| 6705 | Binder.restoreCallingIdentity(token); |
| 6706 | } |
| 6707 | } |
| 6708 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6709 | /** |
| 6710 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6711 | */ |
| 6712 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6713 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | |
| 6715 | final long identity = Binder.clearCallingIdentity(); |
| 6716 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6717 | // NOTE: Before S, this method only set the default phone. |
| 6718 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6719 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6720 | phone.setImsRegistrationState(registered); |
| 6721 | } |
| 6722 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | } finally { |
| 6724 | Binder.restoreCallingIdentity(identity); |
| 6725 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6729 | * Set the network selection mode to automatic. |
| 6730 | * |
| 6731 | */ |
| 6732 | @Override |
| 6733 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6735 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6736 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6737 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6738 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6739 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6740 | final long identity = Binder.clearCallingIdentity(); |
| 6741 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6742 | if (!isActiveSubscription(subId)) { |
| 6743 | return; |
| 6744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6745 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6746 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6747 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6748 | } finally { |
| 6749 | Binder.restoreCallingIdentity(identity); |
| 6750 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6751 | } |
| 6752 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6753 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6754 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6755 | * |
| 6756 | * @param subId the id of the subscription. |
| 6757 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6758 | * the operator to attach to. |
| 6759 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6760 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6761 | * normal network selection next time. |
| 6762 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6763 | */ |
| 6764 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6765 | public boolean setNetworkSelectionModeManual( |
| 6766 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6768 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6769 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6770 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6771 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6772 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6773 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6774 | if (!isActiveSubscription(subId)) { |
| 6775 | return false; |
| 6776 | } |
| 6777 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6778 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6779 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6781 | if (DBG) { |
| 6782 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6783 | + " operator: " + operatorInfo); |
| 6784 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6785 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6786 | } finally { |
| 6787 | Binder.restoreCallingIdentity(identity); |
| 6788 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6789 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6790 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6791 | * Get the manual network selection |
| 6792 | * |
| 6793 | * @param subId the id of the subscription. |
| 6794 | * |
| 6795 | * @return the previously saved user selected PLMN |
| 6796 | */ |
| 6797 | @Override |
| 6798 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6799 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6800 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6801 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6802 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6803 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6804 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6805 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6806 | final long identity = Binder.clearCallingIdentity(); |
| 6807 | try { |
| 6808 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6809 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6810 | } |
| 6811 | |
| 6812 | final Phone phone = getPhone(subId); |
| 6813 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6814 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6815 | } |
| 6816 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6817 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6818 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6819 | } finally { |
| 6820 | Binder.restoreCallingIdentity(identity); |
| 6821 | } |
| 6822 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6823 | |
| 6824 | /** |
| 6825 | * Scans for available networks. |
| 6826 | */ |
| 6827 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6828 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6829 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6831 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6832 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6833 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6834 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6835 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6836 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6837 | .setCallingPid(Binder.getCallingPid()) |
| 6838 | .setCallingUid(Binder.getCallingUid()) |
| 6839 | .setMethod("getCellNetworkScanResults") |
| 6840 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6841 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6842 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6843 | .build()); |
| 6844 | switch (locationResult) { |
| 6845 | case DENIED_HARD: |
| 6846 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6847 | case DENIED_SOFT: |
| 6848 | return null; |
| 6849 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6850 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6851 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6852 | try { |
| 6853 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6854 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6855 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6856 | } finally { |
| 6857 | Binder.restoreCallingIdentity(identity); |
| 6858 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6859 | } |
| 6860 | |
| 6861 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6862 | * Get the call forwarding info, given the call forwarding reason. |
| 6863 | */ |
| 6864 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6865 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6866 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6867 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6868 | |
| 6869 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6870 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6871 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6872 | long identity = Binder.clearCallingIdentity(); |
| 6873 | try { |
| 6874 | if (DBG) { |
| 6875 | log("getCallForwarding: subId " + subId |
| 6876 | + " callForwardingReason" + callForwardingReason); |
| 6877 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6878 | |
| 6879 | Phone phone = getPhone(subId); |
| 6880 | if (phone == null) { |
| 6881 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6882 | callback.onError( |
| 6883 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6884 | } catch (RemoteException e) { |
| 6885 | // ignore |
| 6886 | } |
| 6887 | return; |
| 6888 | } |
| 6889 | |
| 6890 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6891 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6892 | @Override |
| 6893 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6894 | try { |
| 6895 | callback.onCallForwardingInfoAvailable(info); |
| 6896 | } catch (RemoteException e) { |
| 6897 | // ignore |
| 6898 | } |
| 6899 | } |
| 6900 | |
| 6901 | @Override |
| 6902 | public void onError(int error) { |
| 6903 | try { |
| 6904 | callback.onError(error); |
| 6905 | } catch (RemoteException e) { |
| 6906 | // ignore |
| 6907 | } |
| 6908 | } |
| 6909 | }); |
| 6910 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6911 | } finally { |
| 6912 | Binder.restoreCallingIdentity(identity); |
| 6913 | } |
| 6914 | } |
| 6915 | |
| 6916 | /** |
| 6917 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6918 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6919 | */ |
| 6920 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6921 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6922 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6923 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6924 | |
| 6925 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6926 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6927 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6928 | long identity = Binder.clearCallingIdentity(); |
| 6929 | try { |
| 6930 | if (DBG) { |
| 6931 | log("setCallForwarding: subId " + subId |
| 6932 | + " callForwardingInfo" + callForwardingInfo); |
| 6933 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6934 | |
| 6935 | Phone phone = getPhone(subId); |
| 6936 | if (phone == null) { |
| 6937 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6938 | callback.accept( |
| 6939 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6940 | } catch (RemoteException e) { |
| 6941 | // ignore |
| 6942 | } |
| 6943 | return; |
| 6944 | } |
| 6945 | |
| 6946 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6947 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6948 | |
| 6949 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6950 | } finally { |
| 6951 | Binder.restoreCallingIdentity(identity); |
| 6952 | } |
| 6953 | } |
| 6954 | |
| 6955 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6956 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6957 | */ |
| 6958 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6959 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6960 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6961 | |
| 6962 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6963 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 6964 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6965 | long identity = Binder.clearCallingIdentity(); |
| 6966 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6967 | Phone phone = getPhone(subId); |
| 6968 | if (phone == null) { |
| 6969 | try { |
| 6970 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6971 | } catch (RemoteException e) { |
| 6972 | // ignore |
| 6973 | } |
| 6974 | return; |
| 6975 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6976 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6977 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6978 | boolean requireUssd = c.getBoolean( |
| 6979 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6980 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6981 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6982 | if (requireUssd) { |
| 6983 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6984 | getSubscriptionCarrierId(subId)); |
| 6985 | String newUssdCommand = ""; |
| 6986 | try { |
| 6987 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6988 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6989 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6990 | } catch (NullPointerException e) { |
| 6991 | loge("Failed to generate USSD number" + e); |
| 6992 | } |
| 6993 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6994 | mMainThreadHandler, callback, carrierXmlParser, |
| 6995 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6996 | final String ussdCommand = newUssdCommand; |
| 6997 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6998 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6999 | }); |
| 7000 | } else { |
| 7001 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7002 | callback::accept); |
| 7003 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7004 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7005 | } finally { |
| 7006 | Binder.restoreCallingIdentity(identity); |
| 7007 | } |
| 7008 | } |
| 7009 | |
| 7010 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7011 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7012 | */ |
| 7013 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7014 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7015 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7016 | |
| 7017 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7018 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7019 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7020 | long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7022 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7023 | |
| 7024 | Phone phone = getPhone(subId); |
| 7025 | if (phone == null) { |
| 7026 | try { |
| 7027 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7028 | } catch (RemoteException e) { |
| 7029 | // ignore |
| 7030 | } |
| 7031 | return; |
| 7032 | } |
| 7033 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7034 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7035 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7036 | boolean requireUssd = c.getBoolean( |
| 7037 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7038 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7039 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7040 | if (requireUssd) { |
| 7041 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7042 | getSubscriptionCarrierId(subId)); |
| 7043 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7044 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7045 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7046 | String newUssdCommand = ""; |
| 7047 | try { |
| 7048 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7049 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7050 | .makeCommand(ssAction, null); |
| 7051 | } catch (NullPointerException e) { |
| 7052 | loge("Failed to generate USSD number" + e); |
| 7053 | } |
| 7054 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7055 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7056 | final String ussdCommand = newUssdCommand; |
| 7057 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7058 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7059 | }); |
| 7060 | } else { |
| 7061 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7062 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7063 | |
| 7064 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7065 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7066 | } finally { |
| 7067 | Binder.restoreCallingIdentity(identity); |
| 7068 | } |
| 7069 | } |
| 7070 | |
| 7071 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7072 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7073 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7074 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7075 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7076 | * location related information which will be sent if the caller already possess |
| 7077 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7078 | * @param request contains the radio access networks with bands/channels to scan |
| 7079 | * @param messenger callback messenger for scan results or errors |
| 7080 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7081 | * @return the id of the requested scan which can be used to stop the scan. |
| 7082 | */ |
| 7083 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7084 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7085 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7086 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7088 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7089 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7090 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7091 | if (!renounceFineLocationAccess) { |
| 7092 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7093 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7094 | .setCallingPackage(callingPackage) |
| 7095 | .setCallingFeatureId(callingFeatureId) |
| 7096 | .setCallingPid(Binder.getCallingPid()) |
| 7097 | .setCallingUid(Binder.getCallingUid()) |
| 7098 | .setMethod("requestNetworkScan") |
| 7099 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7100 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7101 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7102 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7103 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7104 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7105 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7106 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7107 | if (e != null) { |
| 7108 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7109 | throw e; |
| 7110 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7111 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7112 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7113 | } |
| 7114 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7115 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7116 | |
| 7117 | enforceTelephonyFeatureWithException(callingPackage, |
| 7118 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7119 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7120 | int callingUid = Binder.getCallingUid(); |
| 7121 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7122 | final long identity = Binder.clearCallingIdentity(); |
| 7123 | try { |
| 7124 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7125 | renounceFineLocationAccess, request, messenger, binder, |
| 7126 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7127 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7128 | } finally { |
| 7129 | Binder.restoreCallingIdentity(identity); |
| 7130 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7131 | } |
| 7132 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7133 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7134 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7135 | boolean hasCarrierPriv; |
| 7136 | final long identity = Binder.clearCallingIdentity(); |
| 7137 | try { |
| 7138 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7139 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
| 7142 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7143 | boolean hasNetworkScanPermission = |
| 7144 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7145 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7146 | |
| 7147 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7148 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7149 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7153 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7154 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7155 | return new SecurityException("Specific channels must not be" |
| 7156 | + " scanned without location access."); |
| 7157 | } |
| 7158 | } |
| 7159 | } |
| 7160 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7161 | return null; |
| 7162 | } |
| 7163 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7164 | /** |
| 7165 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7166 | * |
| 7167 | * @param subId id of the subscription |
| 7168 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7169 | */ |
| 7170 | @Override |
| 7171 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7173 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7174 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7175 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7176 | final long identity = Binder.clearCallingIdentity(); |
| 7177 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7178 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | } finally { |
| 7180 | Binder.restoreCallingIdentity(identity); |
| 7181 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7182 | } |
| 7183 | |
| 7184 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7185 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7186 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7187 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7188 | */ |
| 7189 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7190 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7191 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7192 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7193 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7194 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7195 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7196 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7197 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7198 | final long identity = Binder.clearCallingIdentity(); |
| 7199 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7200 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7201 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7202 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7203 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7204 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7205 | } finally { |
| 7206 | Binder.restoreCallingIdentity(identity); |
| 7207 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7208 | } |
| 7209 | |
| 7210 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7211 | * Get the allowed network types for certain reason. |
| 7212 | * |
| 7213 | * @param subId the id of the subscription. |
| 7214 | * @param reason the reason the allowed network type change is taking place |
| 7215 | * @return the allowed network types. |
| 7216 | */ |
| 7217 | @Override |
| 7218 | public long getAllowedNetworkTypesForReason(int subId, |
| 7219 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7220 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7221 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7222 | |
| 7223 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7224 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7225 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7226 | final long identity = Binder.clearCallingIdentity(); |
| 7227 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7228 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7229 | } finally { |
| 7230 | Binder.restoreCallingIdentity(identity); |
| 7231 | } |
| 7232 | } |
| 7233 | |
| 7234 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7235 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7236 | * @param subId subscription id of the sim card |
| 7237 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7238 | * This can be passed following states |
| 7239 | * <ol> |
| 7240 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7241 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7242 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7243 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7244 | * </ol> |
| 7245 | * @return operation result. |
| 7246 | */ |
| 7247 | @Override |
| 7248 | public int setNrDualConnectivityState(int subId, |
| 7249 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7250 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7251 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7252 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7253 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7254 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7255 | } |
| 7256 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7257 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7258 | final long identity = Binder.clearCallingIdentity(); |
| 7259 | try { |
| 7260 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7261 | nrDualConnectivityState, subId, |
| 7262 | workSource); |
| 7263 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7264 | return result; |
| 7265 | } finally { |
| 7266 | Binder.restoreCallingIdentity(identity); |
| 7267 | } |
| 7268 | } |
| 7269 | |
| 7270 | /** |
| 7271 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7272 | * @return true if dual connectivity is enabled else false |
| 7273 | */ |
| 7274 | @Override |
| 7275 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7276 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7277 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7278 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7279 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7280 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7281 | return false; |
| 7282 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7283 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7284 | final long identity = Binder.clearCallingIdentity(); |
| 7285 | try { |
| 7286 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7287 | null, subId, workSource); |
| 7288 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7289 | return isEnabled; |
| 7290 | } finally { |
| 7291 | Binder.restoreCallingIdentity(identity); |
| 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7296 | * Set the allowed network types of the device and |
| 7297 | * provide the reason triggering the allowed network change. |
| 7298 | * |
| 7299 | * @param subId the id of the subscription. |
| 7300 | * @param reason the reason the allowed network type change is taking place |
| 7301 | * @param allowedNetworkTypes the allowed network types. |
| 7302 | * @return true on success; false on any failure. |
| 7303 | */ |
| 7304 | @Override |
| 7305 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7306 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7307 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7309 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7310 | // If the caller only has carrier privileges, then they should not be able to override |
| 7311 | // any network types which were set for security reasons. |
| 7312 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7313 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7314 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7315 | throw new SecurityException( |
| 7316 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7317 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7318 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7319 | |
| 7320 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7321 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7322 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7323 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7324 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7325 | return false; |
| 7326 | } |
| 7327 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7328 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7329 | return false; |
| 7330 | } |
| 7331 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7332 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7333 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7334 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7335 | Phone phone = getPhone(subId); |
| 7336 | if (phone == null) { |
| 7337 | return false; |
| 7338 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7339 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7340 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7341 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7342 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7343 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7344 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7345 | final long identity = Binder.clearCallingIdentity(); |
| 7346 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7347 | Boolean success = (Boolean) sendRequest( |
| 7348 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7349 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7350 | |
| 7351 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7352 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7353 | } finally { |
| 7354 | Binder.restoreCallingIdentity(identity); |
| 7355 | } |
| 7356 | } |
| 7357 | |
| 7358 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7359 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7360 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7361 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7362 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7363 | * @hide |
| 7364 | */ |
| 7365 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7366 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7367 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7368 | |
| 7369 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7370 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7373 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7374 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7375 | if (phone != null) { |
| 7376 | return phone.hasMatchedTetherApnSetting(); |
| 7377 | } else { |
| 7378 | return false; |
| 7379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7380 | } finally { |
| 7381 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7382 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7383 | } |
| 7384 | |
| 7385 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7386 | * Get the user enabled state of Mobile Data. |
| 7387 | * |
| 7388 | * TODO: remove and use isUserDataEnabled. |
| 7389 | * This can't be removed now because some vendor codes |
| 7390 | * calls through ITelephony directly while they should |
| 7391 | * use TelephonyManager. |
| 7392 | * |
| 7393 | * @return true on enabled |
| 7394 | */ |
| 7395 | @Override |
| 7396 | public boolean getDataEnabled(int subId) { |
| 7397 | return isUserDataEnabled(subId); |
| 7398 | } |
| 7399 | |
| 7400 | /** |
| 7401 | * Get whether mobile data is enabled per user setting. |
| 7402 | * |
| 7403 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7404 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7405 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7406 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7407 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7408 | * |
| 7409 | * @return {@code true} if data is enabled else {@code false} |
| 7410 | */ |
| 7411 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7412 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7413 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7414 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7415 | try { |
| 7416 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7417 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7418 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7419 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7420 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7421 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7423 | mApp, subId, functionName); |
| 7424 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7425 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7426 | |
| 7427 | final long identity = Binder.clearCallingIdentity(); |
| 7428 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7429 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7430 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7431 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7432 | if (phone != null) { |
| 7433 | boolean retVal = phone.isUserDataEnabled(); |
| 7434 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7435 | return retVal; |
| 7436 | } else { |
| 7437 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7438 | return false; |
| 7439 | } |
| 7440 | } finally { |
| 7441 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7442 | } |
| 7443 | } |
| 7444 | |
| 7445 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7446 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7447 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7448 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7449 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7450 | * @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] | 7451 | */ |
| 7452 | @Override |
| 7453 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7454 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7455 | try { |
| 7456 | try { |
| 7457 | mApp.enforceCallingOrSelfPermission( |
| 7458 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7459 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7460 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7461 | try { |
| 7462 | mApp.enforceCallingOrSelfPermission( |
| 7463 | android.Manifest.permission.READ_PHONE_STATE, |
| 7464 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7465 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7466 | mApp.enforceCallingOrSelfPermission( |
| 7467 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7468 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7469 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7470 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7471 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7472 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7474 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7475 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7477 | final long identity = Binder.clearCallingIdentity(); |
| 7478 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7479 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7480 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7481 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7482 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7483 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | return retVal; |
| 7485 | } else { |
| 7486 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7487 | return false; |
| 7488 | } |
| 7489 | } finally { |
| 7490 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7491 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7492 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7493 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7494 | /** |
| 7495 | * Check if data is enabled for a specific reason |
| 7496 | * @param subId Subscription index |
| 7497 | * @param reason the reason the data enable change is taking place |
| 7498 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7499 | */ |
| 7500 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7501 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7502 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7503 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7504 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7505 | try { |
| 7506 | mApp.enforceCallingOrSelfPermission( |
| 7507 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7508 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7509 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7510 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7511 | functionName); |
| 7512 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7513 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7514 | try { |
| 7515 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7516 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7517 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7519 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7520 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7521 | } |
| 7522 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7523 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7524 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7525 | |
| 7526 | final long identity = Binder.clearCallingIdentity(); |
| 7527 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7528 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7529 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7530 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7531 | + " reason=" + reason); |
| 7532 | } |
| 7533 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7534 | if (phone != null) { |
| 7535 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7536 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7537 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7538 | return retVal; |
| 7539 | } else { |
| 7540 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7541 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7542 | + subId + " retVal=false"); |
| 7543 | } |
| 7544 | return false; |
| 7545 | } |
| 7546 | } finally { |
| 7547 | Binder.restoreCallingIdentity(identity); |
| 7548 | } |
| 7549 | } |
| 7550 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7551 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7552 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7553 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7554 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7555 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7556 | // No permission needed; this only lets the caller inspect their own status. |
| 7557 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7558 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7559 | |
| 7560 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7561 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7562 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7563 | |
| 7564 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7565 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7566 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7567 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7568 | } |
| 7569 | |
| 7570 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7571 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7572 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7573 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7574 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7575 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7576 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7577 | if (cpt == null) { |
| 7578 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7579 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7580 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7581 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7582 | } |
| 7583 | |
| 7584 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7585 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7586 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7587 | |
| 7588 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7589 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7590 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7591 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7592 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7593 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7594 | Phone phone = getPhone(subId); |
| 7595 | if (phone == null) { |
| 7596 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7597 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7598 | } |
| 7599 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7600 | if (cpt == null) { |
| 7601 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7602 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7603 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7604 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7605 | } |
| 7606 | |
| 7607 | @Override |
| 7608 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7609 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7610 | |
| 7611 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7612 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7613 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7614 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7615 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7616 | } |
| 7617 | |
| 7618 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7619 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7620 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7621 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7622 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7623 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7624 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7625 | if (phone == null) { |
| 7626 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7627 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7628 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7629 | if (cpt == null) { |
| 7630 | continue; |
| 7631 | } |
| 7632 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7633 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7634 | break; |
| 7635 | } |
| 7636 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7637 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7638 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7639 | |
| 7640 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7641 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7642 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7643 | |
| 7644 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7645 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7646 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7647 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7648 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7649 | if (phone == null) { |
| 7650 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7651 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7652 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7653 | if (cpt == null) { |
| 7654 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7655 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7656 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7657 | } |
| 7658 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7659 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7660 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7661 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7662 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7663 | if (phone == null) { |
| 7664 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7665 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7666 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7667 | if (cpt == null) { |
| 7668 | return Collections.emptyList(); |
| 7669 | } |
| 7670 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7671 | } |
| 7672 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7673 | @Override |
| 7674 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7675 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7676 | |
| 7677 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7678 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7679 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7680 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7681 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7682 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7683 | try { |
| 7684 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7685 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7686 | } |
| 7687 | } finally { |
| 7688 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7689 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7690 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7691 | } |
| 7692 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7693 | @Override |
| 7694 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7695 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7696 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7697 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7698 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7699 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7700 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7701 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7702 | if (phone == null) { |
| 7703 | return null; |
| 7704 | } |
| 7705 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7706 | if (cpt == null) { |
| 7707 | return null; |
| 7708 | } |
| 7709 | return cpt.getCarrierServicePackageName(); |
| 7710 | } |
| 7711 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7712 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7713 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7714 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7715 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7716 | return null; |
| 7717 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7718 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7719 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7720 | return null; |
| 7721 | } |
| 7722 | return iccId; |
| 7723 | } |
| 7724 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7725 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7726 | public void setCallComposerStatus(int subId, int status) { |
| 7727 | enforceModifyPermission(); |
| 7728 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7729 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7730 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7731 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7732 | final long identity = Binder.clearCallingIdentity(); |
| 7733 | try { |
| 7734 | Phone phone = getPhone(subId); |
| 7735 | if (phone != null) { |
| 7736 | Phone defaultPhone = phone.getImsPhone(); |
| 7737 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7738 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7739 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7740 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7741 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7742 | } |
| 7743 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7744 | } catch (ImsException e) { |
| 7745 | throw new ServiceSpecificException(e.getCode()); |
| 7746 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7747 | Binder.restoreCallingIdentity(identity); |
| 7748 | } |
| 7749 | } |
| 7750 | |
| 7751 | @Override |
| 7752 | public int getCallComposerStatus(int subId) { |
| 7753 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7754 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7755 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7756 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7757 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
| 7760 | Phone phone = getPhone(subId); |
| 7761 | if (phone != null) { |
| 7762 | Phone defaultPhone = phone.getImsPhone(); |
| 7763 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7764 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7765 | return imsPhone.getCallComposerStatus(); |
| 7766 | } |
| 7767 | } |
| 7768 | } finally { |
| 7769 | Binder.restoreCallingIdentity(identity); |
| 7770 | } |
| 7771 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7772 | } |
| 7773 | |
| 7774 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7775 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7776 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7777 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7778 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7779 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7780 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7781 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7782 | "setLine1NumberForDisplayForSubscriber"); |
| 7783 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7784 | final long identity = Binder.clearCallingIdentity(); |
| 7785 | try { |
| 7786 | final String iccId = getIccId(subId); |
| 7787 | final Phone phone = getPhone(subId); |
| 7788 | if (phone == null) { |
| 7789 | return false; |
| 7790 | } |
| 7791 | final String subscriberId = phone.getSubscriberId(); |
| 7792 | |
| 7793 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7794 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7795 | + subscriberId + " to " + number); |
| 7796 | } |
| 7797 | |
| 7798 | if (TextUtils.isEmpty(iccId)) { |
| 7799 | return false; |
| 7800 | } |
| 7801 | |
| 7802 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7803 | |
| 7804 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7805 | if (alphaTag == null) { |
| 7806 | editor.remove(alphaTagPrefKey); |
| 7807 | } else { |
| 7808 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7809 | } |
| 7810 | |
| 7811 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7812 | // track all merged IMSIs based on line number |
| 7813 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7814 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7815 | if (number == null) { |
| 7816 | editor.remove(numberPrefKey); |
| 7817 | editor.remove(subscriberPrefKey); |
| 7818 | } else { |
| 7819 | editor.putString(numberPrefKey, number); |
| 7820 | editor.putString(subscriberPrefKey, subscriberId); |
| 7821 | } |
| 7822 | |
| 7823 | editor.commit(); |
| 7824 | return true; |
| 7825 | } finally { |
| 7826 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7827 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7828 | } |
| 7829 | |
| 7830 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7831 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7832 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7833 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7834 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7835 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7836 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7837 | return null; |
| 7838 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7839 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7840 | enforceTelephonyFeatureWithException(callingPackage, |
| 7841 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7842 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7843 | final long identity = Binder.clearCallingIdentity(); |
| 7844 | try { |
| 7845 | String iccId = getIccId(subId); |
| 7846 | if (iccId != null) { |
| 7847 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7848 | if (DBG_MERGE) { |
| 7849 | log("getLine1NumberForDisplay returning " |
| 7850 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7851 | } |
| 7852 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7853 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7855 | return null; |
| 7856 | } finally { |
| 7857 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7858 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7862 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7863 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7864 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7865 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7866 | return null; |
| 7867 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7868 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7869 | final long identity = Binder.clearCallingIdentity(); |
| 7870 | try { |
| 7871 | String iccId = getIccId(subId); |
| 7872 | if (iccId != null) { |
| 7873 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7874 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7875 | } |
| 7876 | return null; |
| 7877 | } finally { |
| 7878 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7879 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7880 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7881 | |
| 7882 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7883 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7884 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7885 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7886 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7887 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7888 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7889 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7890 | return null; |
| 7891 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7892 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7893 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7894 | // the process, where TelephonyManager was instantiated. |
| 7895 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7896 | final long identity = Binder.clearCallingIdentity(); |
| 7897 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7898 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7899 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7900 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7901 | |
| 7902 | // Figure out what subscribers are currently active |
| 7903 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7904 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7905 | // Only consider subs which match the current subId |
| 7906 | // This logic can be simplified. See b/131189269 for progress. |
| 7907 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7908 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7909 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7910 | |
| 7911 | // First pass, find a number override for an active subscriber |
| 7912 | String mergeNumber = null; |
| 7913 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7914 | for (String key : prefs.keySet()) { |
| 7915 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7916 | final String subscriberId = (String) prefs.get(key); |
| 7917 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7918 | final String iccId = key.substring( |
| 7919 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7920 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7921 | mergeNumber = (String) prefs.get(numberKey); |
| 7922 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7923 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7924 | + " for active subscriber " + subscriberId); |
| 7925 | } |
| 7926 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7927 | break; |
| 7928 | } |
| 7929 | } |
| 7930 | } |
| 7931 | } |
| 7932 | |
| 7933 | // Shortcut when no active merged subscribers |
| 7934 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7935 | return null; |
| 7936 | } |
| 7937 | |
| 7938 | // Second pass, find all subscribers under that line override |
| 7939 | final ArraySet<String> result = new ArraySet<>(); |
| 7940 | for (String key : prefs.keySet()) { |
| 7941 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7942 | final String number = (String) prefs.get(key); |
| 7943 | if (mergeNumber.equals(number)) { |
| 7944 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7945 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7946 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7947 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7948 | result.add(subscriberId); |
| 7949 | } |
| 7950 | } |
| 7951 | } |
| 7952 | } |
| 7953 | |
| 7954 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7955 | Arrays.sort(resultArray); |
| 7956 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7957 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7958 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7959 | } |
| 7960 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7961 | } finally { |
| 7962 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7963 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7964 | } |
| 7965 | |
| 7966 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7967 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7968 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7969 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7970 | enforceTelephonyFeatureWithException(callingPackage, |
| 7971 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 7972 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7973 | final long identity = Binder.clearCallingIdentity(); |
| 7974 | try { |
| 7975 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7976 | TelephonyManager.class); |
| 7977 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7978 | if (subscriberId == null) { |
| 7979 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7980 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7981 | + subId); |
| 7982 | } |
| 7983 | return null; |
| 7984 | } |
| 7985 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7986 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7987 | .getSubscriptionInfo(subId); |
| 7988 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7989 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7990 | if (groupUuid == null) { |
| 7991 | return new String[]{subscriberId}; |
| 7992 | } |
| 7993 | |
| 7994 | // Get all subscriberIds from the group. |
| 7995 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7996 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7997 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7998 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7999 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8000 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8001 | if (subscriberId != null) { |
| 8002 | mergedSubscriberIds.add(subscriberId); |
| 8003 | } |
| 8004 | } |
| 8005 | |
| 8006 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8007 | } finally { |
| 8008 | Binder.restoreCallingIdentity(identity); |
| 8009 | |
| 8010 | } |
| 8011 | } |
| 8012 | |
| 8013 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8014 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8015 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8016 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8017 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8018 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8019 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8020 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8021 | final long identity = Binder.clearCallingIdentity(); |
| 8022 | try { |
| 8023 | final Phone phone = getPhone(subId); |
| 8024 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8025 | } finally { |
| 8026 | Binder.restoreCallingIdentity(identity); |
| 8027 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8028 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8029 | |
| 8030 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8031 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8032 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8033 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8034 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8035 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8036 | |
| 8037 | final long identity = Binder.clearCallingIdentity(); |
| 8038 | try { |
| 8039 | final Phone phone = getPhone(subId); |
| 8040 | if (phone == null) { |
| 8041 | return false; |
| 8042 | } |
| 8043 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8044 | cdmaNonRoamingList); |
| 8045 | } finally { |
| 8046 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8047 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8048 | } |
| 8049 | |
| 8050 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8051 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8052 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8053 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8054 | if (phone == null) { |
| 8055 | return raf; |
| 8056 | } |
| 8057 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8058 | try { |
| 8059 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8060 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8061 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8062 | } catch (SecurityException e) { |
| 8063 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8064 | throw e; |
| 8065 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8066 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8067 | enforceTelephonyFeatureWithException(callingPackage, |
| 8068 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8070 | final long identity = Binder.clearCallingIdentity(); |
| 8071 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8072 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8073 | } finally { |
| 8074 | Binder.restoreCallingIdentity(identity); |
| 8075 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8076 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8077 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8078 | |
| 8079 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8080 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8081 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8082 | try { |
| 8083 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8084 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8085 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8086 | } |
| 8087 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8088 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8089 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8090 | |
| 8091 | enforceTelephonyFeatureWithException(callingPackage, |
| 8092 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8093 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8094 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8095 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8096 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8097 | throw new SecurityException("App must be the dialer role holder to" |
| 8098 | + " upload a call composer pic"); |
| 8099 | } |
| 8100 | |
| 8101 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8102 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8103 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8104 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8105 | boolean readUntilEnd = false; |
| 8106 | int totalBytesRead = 0; |
| 8107 | byte[] buffer = new byte[16 * 1024]; |
| 8108 | while (true) { |
| 8109 | int numRead; |
| 8110 | try { |
| 8111 | numRead = input.read(buffer); |
| 8112 | } catch (IOException e) { |
| 8113 | try { |
| 8114 | fd.checkError(); |
| 8115 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8116 | null); |
| 8117 | } catch (IOException e1) { |
| 8118 | // This means that the other side closed explicitly with an error. If this |
| 8119 | // happens, log and ignore. |
| 8120 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8121 | } |
| 8122 | break; |
| 8123 | } |
| 8124 | if (numRead == -1) { |
| 8125 | readUntilEnd = true; |
| 8126 | break; |
| 8127 | } |
| 8128 | totalBytesRead += numRead; |
| 8129 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8130 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8131 | try { |
| 8132 | input.close(); |
| 8133 | } catch (IOException e) { |
| 8134 | // ignore |
| 8135 | } |
| 8136 | break; |
| 8137 | } |
| 8138 | output.write(buffer, 0, numRead); |
| 8139 | } |
| 8140 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8141 | // close is above, where the picture size is too big. |
| 8142 | |
| 8143 | try { |
| 8144 | fd.checkError(); |
| 8145 | } catch (IOException e) { |
| 8146 | loge("Remote end for call composer closed with an error: " + e); |
| 8147 | return; |
| 8148 | } |
| 8149 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8150 | if (!readUntilEnd) { |
| 8151 | loge("Did not finish reading entire image; aborting"); |
| 8152 | return; |
| 8153 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8154 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8155 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8156 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8157 | new CallComposerPictureTransfer.Factory() {}, |
| 8158 | imageData, |
| 8159 | (result) -> { |
| 8160 | if (result.first != null) { |
| 8161 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8162 | Bundle outputResult = new Bundle(); |
| 8163 | outputResult.putParcelable( |
| 8164 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8165 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8166 | outputResult); |
| 8167 | } else { |
| 8168 | callback.send(result.second, null); |
| 8169 | } |
| 8170 | } |
| 8171 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8172 | }); |
| 8173 | } |
| 8174 | |
| 8175 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8176 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8177 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8178 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8179 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8180 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8181 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8182 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8183 | final long identity = Binder.clearCallingIdentity(); |
| 8184 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8185 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8186 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8187 | } finally { |
| 8188 | Binder.restoreCallingIdentity(identity); |
| 8189 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8190 | } |
| 8191 | |
| 8192 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8193 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8194 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8195 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8196 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8197 | return false; |
| 8198 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8199 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8200 | enforceTelephonyFeatureWithException(callingPackage, |
| 8201 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8202 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8203 | final long identity = Binder.clearCallingIdentity(); |
| 8204 | try { |
| 8205 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8206 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8207 | // In the long run, we may instead need to check if there exists a connection service |
| 8208 | // which can support video calling. |
| 8209 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8210 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8211 | return imsManager.isVtEnabledByPlatform() |
| 8212 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8213 | && imsManager.isVtEnabledByUser(); |
| 8214 | } finally { |
| 8215 | Binder.restoreCallingIdentity(identity); |
| 8216 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8217 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8218 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8219 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8220 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8221 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8222 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8223 | mApp, subId, callingPackage, callingFeatureId, |
| 8224 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8225 | return false; |
| 8226 | } |
| 8227 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8228 | enforceTelephonyFeatureWithException(callingPackage, |
| 8229 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8230 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8231 | final long identity = Binder.clearCallingIdentity(); |
| 8232 | try { |
| 8233 | CarrierConfigManager configManager = |
| 8234 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8235 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8236 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8237 | } finally { |
| 8238 | Binder.restoreCallingIdentity(identity); |
| 8239 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8240 | } |
| 8241 | |
| 8242 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8243 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8244 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8245 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8246 | return false; |
| 8247 | } |
| 8248 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8249 | enforceTelephonyFeatureWithException(callingPackage, |
| 8250 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8252 | final long identity = Binder.clearCallingIdentity(); |
| 8253 | try { |
| 8254 | CarrierConfigManager configManager = |
| 8255 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8256 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8257 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8258 | } finally { |
| 8259 | Binder.restoreCallingIdentity(identity); |
| 8260 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8261 | } |
| 8262 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8263 | @Override |
| 8264 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8265 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8266 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8267 | } |
| 8268 | |
| 8269 | @Override |
| 8270 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8271 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8272 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8273 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8274 | final long identity = Binder.clearCallingIdentity(); |
| 8275 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8276 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
| 8279 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8280 | } |
| 8281 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8282 | /** |
| 8283 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8284 | * support for the feature and device firmware support. |
| 8285 | * |
| 8286 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8287 | */ |
| 8288 | @Override |
| 8289 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8290 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8291 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8294 | final Phone phone = getPhone(subscriptionId); |
| 8295 | if (phone == null) { |
| 8296 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8297 | return false; |
| 8298 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8299 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8300 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8302 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8303 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8304 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8305 | return isCarrierSupported && isDeviceSupported; |
| 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
| 8308 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8309 | } |
| 8310 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8311 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8312 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8313 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8314 | * 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] | 8315 | */ |
| 8316 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8317 | final long identity = Binder.clearCallingIdentity(); |
| 8318 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8319 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8320 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8321 | return false; |
| 8322 | } |
| 8323 | } |
| 8324 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8325 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8326 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8327 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8328 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8329 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8330 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8331 | } finally { |
| 8332 | Binder.restoreCallingIdentity(identity); |
| 8333 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8334 | } |
| 8335 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8336 | @Deprecated |
| 8337 | @Override |
| 8338 | public String getDeviceId(String callingPackage) { |
| 8339 | return getDeviceIdWithFeature(callingPackage, null); |
| 8340 | } |
| 8341 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8342 | /** |
| 8343 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8344 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8345 | * |
| 8346 | * <p>Requires Permission: |
| 8347 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8348 | */ |
| 8349 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8350 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8351 | try { |
| 8352 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8353 | } catch (SecurityException se) { |
| 8354 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8355 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8356 | + Binder.getCallingUid()); |
| 8357 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8358 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8359 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8360 | return null; |
| 8361 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8362 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8363 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8364 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8365 | return null; |
| 8366 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8367 | |
| 8368 | final long identity = Binder.clearCallingIdentity(); |
| 8369 | try { |
| 8370 | return phone.getDeviceId(); |
| 8371 | } finally { |
| 8372 | Binder.restoreCallingIdentity(identity); |
| 8373 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8374 | } |
| 8375 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8376 | /** |
| 8377 | * {@hide} |
| 8378 | * Returns the IMS Registration Status on a particular subid |
| 8379 | * |
| 8380 | * @param subId |
| 8381 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8382 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8383 | Phone phone = getPhone(subId); |
| 8384 | if (phone != null) { |
| 8385 | return phone.isImsRegistered(); |
| 8386 | } else { |
| 8387 | return false; |
| 8388 | } |
| 8389 | } |
| 8390 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8391 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8392 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8393 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8395 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8396 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8397 | } |
| 8398 | final long identity = Binder.clearCallingIdentity(); |
| 8399 | try { |
| 8400 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8401 | } finally { |
| 8402 | Binder.restoreCallingIdentity(identity); |
| 8403 | } |
| 8404 | } |
| 8405 | |
| 8406 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8407 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8408 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8409 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8410 | mApp, |
| 8411 | subscriptionId, |
| 8412 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8413 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8414 | |
| 8415 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8416 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8417 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8418 | final long identity = Binder.clearCallingIdentity(); |
| 8419 | try { |
| 8420 | Phone phone = getPhone(subscriptionId); |
| 8421 | if (phone == null) { |
| 8422 | return null; |
| 8423 | } |
| 8424 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8425 | } finally { |
| 8426 | Binder.restoreCallingIdentity(identity); |
| 8427 | } |
| 8428 | } |
| 8429 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8430 | /** |
| 8431 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8432 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8433 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8434 | final long identity = Binder.clearCallingIdentity(); |
| 8435 | try { |
| 8436 | Phone phone = getPhone(subId); |
| 8437 | if (phone != null) { |
| 8438 | return phone.isWifiCallingEnabled(); |
| 8439 | } else { |
| 8440 | return false; |
| 8441 | } |
| 8442 | } finally { |
| 8443 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8444 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8445 | } |
| 8446 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8447 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8448 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8449 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8450 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8451 | final long identity = Binder.clearCallingIdentity(); |
| 8452 | try { |
| 8453 | Phone phone = getPhone(subId); |
| 8454 | if (phone != null) { |
| 8455 | return phone.isVideoEnabled(); |
| 8456 | } else { |
| 8457 | return false; |
| 8458 | } |
| 8459 | } finally { |
| 8460 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8461 | } |
| 8462 | } |
| 8463 | |
| 8464 | /** |
| 8465 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8466 | * defined in {@link ImsRegistrationImplBase}. |
| 8467 | */ |
| 8468 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8469 | final long identity = Binder.clearCallingIdentity(); |
| 8470 | try { |
| 8471 | Phone phone = getPhone(subId); |
| 8472 | if (phone != null) { |
| 8473 | return phone.getImsRegistrationTech(); |
| 8474 | } else { |
| 8475 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8476 | } |
| 8477 | } finally { |
| 8478 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8479 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8480 | } |
| 8481 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8482 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8483 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8484 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8485 | |
| 8486 | enforceTelephonyFeatureWithException(callingPackage, |
| 8487 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8488 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8489 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8490 | return; |
| 8491 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8492 | Phone defaultPhone = getDefaultPhone(); |
| 8493 | if (defaultPhone != null) { |
| 8494 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8495 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8496 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8497 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8498 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8499 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8500 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8501 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8502 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8503 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8504 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8505 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8506 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8507 | setDataRoamingEnabled(subId, phone == null ? false |
| 8508 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8509 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8510 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8511 | // There has been issues when Sms raw table somehow stores orphan |
| 8512 | // fragments. They lead to garbled message when new fragments come |
| 8513 | // in and combined with those stale ones. In case this happens again, |
| 8514 | // user can reset all network settings which will clean up this table. |
| 8515 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8516 | // Clean up IMS settings as well here. |
| 8517 | int slotId = getSlotIndex(subId); |
| 8518 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8519 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8520 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8521 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8522 | if (defaultPhone == null) { |
| 8523 | return; |
| 8524 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8525 | // Erase modem config if erase modem on network setting is enabled. |
| 8526 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8527 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8528 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8529 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8530 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8531 | |
| 8532 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8533 | } finally { |
| 8534 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8535 | } |
| 8536 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8537 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8538 | @VisibleForTesting |
| 8539 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8540 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8541 | return; |
| 8542 | } |
| 8543 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8544 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8545 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8546 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8547 | "user=" + defaultNetworkType); |
| 8548 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8549 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8550 | defaultNetworkType, null); |
| 8551 | } |
| 8552 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8553 | private void cleanUpSmsRawTable(Context context) { |
| 8554 | ContentResolver resolver = context.getContentResolver(); |
| 8555 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8556 | resolver.delete(uri, null, null); |
| 8557 | } |
| 8558 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8559 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8560 | public String getSimLocaleForSubscriber(int subId) { |
| 8561 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8562 | |
| 8563 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8564 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8565 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8566 | final Phone phone = getPhone(subId); |
| 8567 | if (phone == null) { |
| 8568 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8569 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | final long identity = Binder.clearCallingIdentity(); |
| 8572 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8573 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8574 | phone.getContext().getOpPackageName(), |
| 8575 | phone.getContext().getAttributionTag()); |
| 8576 | if (info == null) { |
| 8577 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8578 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8579 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8580 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8581 | // preferences (EF-PL and EF-LI)... |
| 8582 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8583 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8584 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8585 | if (localeFromDefaultSim != null) { |
| 8586 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8587 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8588 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8589 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8590 | } else { |
| 8591 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8592 | } |
| 8593 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8594 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8595 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8596 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8597 | // the SIM and carrier preferences does not include a country we add the country |
| 8598 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8599 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8600 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8601 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8602 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8603 | } |
| 8604 | |
| 8605 | if (DBG) log("No locale found - returning null"); |
| 8606 | return null; |
| 8607 | } finally { |
| 8608 | Binder.restoreCallingIdentity(identity); |
| 8609 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8610 | } |
| 8611 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8612 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8613 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8614 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8615 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8616 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8617 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8618 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8619 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8620 | return localeTag; |
| 8621 | } |
| 8622 | } |
| 8623 | return inputLocale.toLanguageTag(); |
| 8624 | } |
| 8625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8626 | /** |
| 8627 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8628 | */ |
| 8629 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8630 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8631 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8632 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8633 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8634 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8635 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8636 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8637 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8638 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8639 | * representing the state of the modem. |
| 8640 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8641 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8642 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8643 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8644 | */ |
| 8645 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8646 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8647 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8648 | |
| 8649 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8650 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8651 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8652 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8653 | |
| 8654 | final long identity = Binder.clearCallingIdentity(); |
| 8655 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8656 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8657 | } finally { |
| 8658 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8659 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8660 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8661 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8662 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8663 | // less than total activity duration. |
| 8664 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8665 | if (info == null) { |
| 8666 | return false; |
| 8667 | } |
| 8668 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8669 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8670 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8671 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8672 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8673 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8674 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8675 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8676 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8677 | } |
| 8678 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8679 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8680 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8681 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8682 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8683 | |
| 8684 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8685 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8686 | } |
| 8687 | |
| 8688 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8689 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8690 | rat, |
| 8691 | freq, |
| 8692 | info.getReceiveTimeMillis(rat, freq) |
| 8693 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8694 | } |
| 8695 | |
| 8696 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8697 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8698 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8699 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8700 | |
| 8701 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8702 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8703 | } |
| 8704 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8705 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8706 | rat, |
| 8707 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8708 | } |
| 8709 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8710 | /** |
| 8711 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8712 | * @param info recent ModemActivityInfo |
| 8713 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8714 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8715 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8716 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8717 | boolean matched; |
| 8718 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8719 | matched = false; |
| 8720 | int rat = info.getSpecificInfoRat(i); |
| 8721 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8722 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8723 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8724 | //if it already exists |
| 8725 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8726 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8727 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8728 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8729 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8730 | updateLastModemActivityInfo(info, rat, freq); |
| 8731 | matched = true; |
| 8732 | } |
| 8733 | } else { |
| 8734 | updateLastModemActivityInfo(info, rat); |
| 8735 | matched = true; |
| 8736 | } |
| 8737 | } |
| 8738 | } |
| 8739 | |
| 8740 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8741 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8742 | new ActivityStatsTechSpecificInfo( |
| 8743 | rat, |
| 8744 | freq, |
| 8745 | info.getTransmitTimeMillis(rat, freq), |
| 8746 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8747 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8748 | } |
| 8749 | } |
| 8750 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8751 | mLastModemActivitySpecificInfo = |
| 8752 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8753 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8754 | |
| 8755 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8756 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8757 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8758 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8759 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8760 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8761 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8762 | |
| 8763 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8764 | new ModemActivityInfo( |
| 8765 | mLastModemActivityInfo.getTimestampMillis(), |
| 8766 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8767 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8768 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8769 | } |
| 8770 | |
| 8771 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8772 | ActivityStatsTechSpecificInfo[] info) { |
| 8773 | int infoSize = info.length; |
| 8774 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8775 | for (int i = 0; i < infoSize; i++) { |
| 8776 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8777 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8778 | info[i].getTransmitTimeMillis(), |
| 8779 | (int) info[i].getReceiveTimeMillis()); |
| 8780 | } |
| 8781 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8782 | } |
| 8783 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8784 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8785 | * Returns the service state information on specified subscription. |
| 8786 | */ |
| 8787 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8788 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8789 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8790 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8791 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8792 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8793 | return null; |
| 8794 | } |
| 8795 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8796 | enforceTelephonyFeatureWithException(callingPackage, |
| 8797 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8798 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8799 | boolean hasFinePermission = false; |
| 8800 | boolean hasCoarsePermission = false; |
| 8801 | if (!renounceFineLocationAccess) { |
| 8802 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8803 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8804 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8805 | .setCallingPackage(callingPackage) |
| 8806 | .setCallingFeatureId(callingFeatureId) |
| 8807 | .setCallingPid(Binder.getCallingPid()) |
| 8808 | .setCallingUid(Binder.getCallingUid()) |
| 8809 | .setMethod("getServiceStateForSubscriber") |
| 8810 | .setLogAsInfo(true) |
| 8811 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8812 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8813 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8814 | .build()); |
| 8815 | hasFinePermission = |
| 8816 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8817 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8818 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8819 | if (!renounceCoarseLocationAccess) { |
| 8820 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8821 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8822 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8823 | .setCallingPackage(callingPackage) |
| 8824 | .setCallingFeatureId(callingFeatureId) |
| 8825 | .setCallingPid(Binder.getCallingPid()) |
| 8826 | .setCallingUid(Binder.getCallingUid()) |
| 8827 | .setMethod("getServiceStateForSubscriber") |
| 8828 | .setLogAsInfo(true) |
| 8829 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8830 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8831 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8832 | .build()); |
| 8833 | hasCoarsePermission = |
| 8834 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8835 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8836 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8837 | final Phone phone = getPhone(subId); |
| 8838 | if (phone == null) { |
| 8839 | return null; |
| 8840 | } |
| 8841 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8842 | final long identity = Binder.clearCallingIdentity(); |
| 8843 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8844 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8845 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8846 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8847 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8848 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8849 | .getSubscriptionInfoInternal(subId); |
| 8850 | if (subInfo == null || !subInfo.isActive()) { |
| 8851 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8852 | + "subId=" + subId); |
| 8853 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8854 | } |
| 8855 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8856 | ServiceState ss = phone.getServiceState(); |
| 8857 | |
| 8858 | // Scrub out the location info in ServiceState depending on what level of access |
| 8859 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8860 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8861 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8862 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8863 | } finally { |
| 8864 | Binder.restoreCallingIdentity(identity); |
| 8865 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8866 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8867 | |
| 8868 | /** |
| 8869 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8870 | * |
| 8871 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8872 | * voicemail ringtone. |
| 8873 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8874 | * PhoneAccount. |
| 8875 | */ |
| 8876 | @Override |
| 8877 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8878 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8879 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8880 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8881 | final long identity = Binder.clearCallingIdentity(); |
| 8882 | try { |
| 8883 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8884 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8885 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8886 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8888 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8889 | } finally { |
| 8890 | Binder.restoreCallingIdentity(identity); |
| 8891 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8892 | } |
| 8893 | |
| 8894 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8895 | * Sets the per-account voicemail ringtone. |
| 8896 | * |
| 8897 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8898 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8899 | * |
| 8900 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8901 | * voicemail ringtone. |
| 8902 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8903 | * PhoneAccount. |
| 8904 | */ |
| 8905 | @Override |
| 8906 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8907 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8908 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8909 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8910 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8911 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8913 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8914 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8915 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8916 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8917 | enforceTelephonyFeatureWithException(callingPackage, |
| 8918 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8919 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8920 | final long identity = Binder.clearCallingIdentity(); |
| 8921 | try { |
| 8922 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8923 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8924 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8925 | } |
| 8926 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8927 | } finally { |
| 8928 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8929 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8930 | } |
| 8931 | |
| 8932 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8933 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8934 | * |
| 8935 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8936 | * voicemail vibration setting. |
| 8937 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8938 | */ |
| 8939 | @Override |
| 8940 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8941 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8942 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8943 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8944 | final long identity = Binder.clearCallingIdentity(); |
| 8945 | try { |
| 8946 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8947 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8948 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8949 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8951 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8952 | } finally { |
| 8953 | Binder.restoreCallingIdentity(identity); |
| 8954 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8955 | } |
| 8956 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8957 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8958 | * Sets the per-account voicemail vibration. |
| 8959 | * |
| 8960 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8961 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8962 | * |
| 8963 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8964 | * voicemail vibration setting. |
| 8965 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8966 | * specific PhoneAccount. |
| 8967 | */ |
| 8968 | @Override |
| 8969 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8970 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8971 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8972 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8973 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8974 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8976 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8977 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8978 | } |
| 8979 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8980 | enforceTelephonyFeatureWithException(callingPackage, |
| 8981 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 8982 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8983 | final long identity = Binder.clearCallingIdentity(); |
| 8984 | try { |
| 8985 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8986 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8987 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8988 | } |
| 8989 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8990 | } finally { |
| 8991 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8992 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8993 | } |
| 8994 | |
| 8995 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8996 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8997 | * |
| 8998 | * @throws SecurityException if the caller does not have the required permission |
| 8999 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9000 | @VisibleForTesting |
| 9001 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9002 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9003 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9004 | } |
| 9005 | |
| 9006 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9007 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9008 | * permission. |
| 9009 | * |
| 9010 | * @throws SecurityException if the caller does not have the required permission |
| 9011 | */ |
| 9012 | private void enforceSendSmsPermission() { |
| 9013 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9014 | } |
| 9015 | |
| 9016 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9017 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9018 | * users permission. |
| 9019 | * |
| 9020 | * @throws SecurityException if the caller does not have the required permission |
| 9021 | */ |
| 9022 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9023 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9024 | } |
| 9025 | |
| 9026 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9027 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9028 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9029 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9030 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9031 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9032 | final long identity = Binder.clearCallingIdentity(); |
| 9033 | try { |
| 9034 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9035 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9036 | if (componentName == null) { |
| 9037 | throw new SecurityException( |
| 9038 | "Caller not current active visual voicemail package[null]"); |
| 9039 | } |
| 9040 | String vvmPackage = componentName.getPackageName(); |
| 9041 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9042 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9043 | } |
| 9044 | } finally { |
| 9045 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9046 | } |
| 9047 | } |
| 9048 | |
| 9049 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9050 | * Return the application ID for the app type. |
| 9051 | * |
| 9052 | * @param subId the subscription ID that this request applies to. |
| 9053 | * @param appType the uicc app type. |
| 9054 | * @return Application ID for specificied app type, or null if no uicc. |
| 9055 | */ |
| 9056 | @Override |
| 9057 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9058 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9059 | |
| 9060 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9061 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9062 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9063 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9064 | |
| 9065 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9066 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9067 | if (phone == null) { |
| 9068 | return null; |
| 9069 | } |
| 9070 | String aid = null; |
| 9071 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9072 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9073 | .getApplicationByType(appType).getAid(); |
| 9074 | } catch (Exception e) { |
| 9075 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9076 | } |
| 9077 | return aid; |
| 9078 | } finally { |
| 9079 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9080 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9081 | } |
| 9082 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9083 | /** |
| 9084 | * Return the Electronic Serial Number. |
| 9085 | * |
| 9086 | * @param subId the subscription ID that this request applies to. |
| 9087 | * @return ESN or null if error. |
| 9088 | */ |
| 9089 | @Override |
| 9090 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9091 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9092 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9093 | |
| 9094 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9095 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9096 | if (phone == null) { |
| 9097 | return null; |
| 9098 | } |
| 9099 | String esn = null; |
| 9100 | try { |
| 9101 | esn = phone.getEsn(); |
| 9102 | } catch (Exception e) { |
| 9103 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9104 | } |
| 9105 | return esn; |
| 9106 | } finally { |
| 9107 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9108 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9109 | } |
| 9110 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9111 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9112 | * Return the Preferred Roaming List Version. |
| 9113 | * |
| 9114 | * @param subId the subscription ID that this request applies to. |
| 9115 | * @return PRLVersion or null if error. |
| 9116 | */ |
| 9117 | @Override |
| 9118 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9119 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9120 | |
| 9121 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9122 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9123 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9124 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9125 | |
| 9126 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9127 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9128 | if (phone == null) { |
| 9129 | return null; |
| 9130 | } |
| 9131 | String cdmaPrlVersion = null; |
| 9132 | try { |
| 9133 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9134 | } catch (Exception e) { |
| 9135 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9136 | } |
| 9137 | return cdmaPrlVersion; |
| 9138 | } finally { |
| 9139 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9140 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9141 | } |
| 9142 | |
| 9143 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9144 | * Get snapshot of Telephony histograms |
| 9145 | * @return List of Telephony histograms |
| 9146 | * @hide |
| 9147 | */ |
| 9148 | @Override |
| 9149 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9151 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9152 | |
| 9153 | final long identity = Binder.clearCallingIdentity(); |
| 9154 | try { |
| 9155 | return RIL.getTelephonyRILTimingHistograms(); |
| 9156 | } finally { |
| 9157 | Binder.restoreCallingIdentity(identity); |
| 9158 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9159 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9160 | |
| 9161 | /** |
| 9162 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9163 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9164 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9165 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9166 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9167 | * @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] | 9168 | */ |
| 9169 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9170 | @TelephonyManager.SetCarrierRestrictionResult |
| 9171 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9172 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9173 | |
| 9174 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9175 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9176 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9177 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9178 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9179 | if (carrierRestrictionRules == null) { |
| 9180 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9181 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9182 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9183 | final long identity = Binder.clearCallingIdentity(); |
| 9184 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9185 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9186 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9187 | } finally { |
| 9188 | Binder.restoreCallingIdentity(identity); |
| 9189 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9190 | } |
| 9191 | |
| 9192 | /** |
| 9193 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9194 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9195 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9196 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9197 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9198 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9199 | */ |
| 9200 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9201 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9202 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9203 | |
| 9204 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9205 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9206 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9207 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9208 | |
| 9209 | final long identity = Binder.clearCallingIdentity(); |
| 9210 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9211 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9212 | if (response instanceof CarrierRestrictionRules) { |
| 9213 | return (CarrierRestrictionRules) response; |
| 9214 | } |
| 9215 | // Response is an Exception of some kind, |
| 9216 | // which is signalled to the user as a NULL retval |
| 9217 | return null; |
| 9218 | } catch (Exception e) { |
| 9219 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9220 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9221 | } finally { |
| 9222 | Binder.restoreCallingIdentity(identity); |
| 9223 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9224 | } |
| 9225 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9226 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9227 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9228 | * through the callback. |
| 9229 | * |
| 9230 | * @param callback The callback that will be used to send the result. |
| 9231 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9232 | * the caller is not allowlisted. |
| 9233 | */ |
| 9234 | @Override |
| 9235 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9236 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9237 | |
| 9238 | enforceTelephonyFeatureWithException(packageName, |
| 9239 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9240 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9241 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9242 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9243 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9244 | throw new SecurityException("Not an authorized caller"); |
| 9245 | } |
| 9246 | final long identity = Binder.clearCallingIdentity(); |
| 9247 | try { |
| 9248 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9249 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9250 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9251 | } finally { |
| 9252 | Binder.restoreCallingIdentity(identity); |
| 9253 | } |
| 9254 | } |
| 9255 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9256 | @Override |
| 9257 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9258 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9259 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9260 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9261 | } |
| 9262 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9263 | @VisibleForTesting |
| 9264 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9265 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9266 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9267 | } |
| 9268 | |
| 9269 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9270 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9271 | * @param subId the subscription ID that this action applies to. |
| 9272 | * @param enabled control enable or disable radio. |
| 9273 | * {@hide} |
| 9274 | */ |
| 9275 | @Override |
| 9276 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9277 | enforceModifyPermission(); |
| 9278 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9279 | |
| 9280 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9281 | if (phone == null) { |
| 9282 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9283 | return; |
| 9284 | } |
| 9285 | try { |
| 9286 | phone.carrierActionSetRadioEnabled(enabled); |
| 9287 | } catch (Exception e) { |
| 9288 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9289 | } finally { |
| 9290 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9291 | } |
| 9292 | } |
| 9293 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9294 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9295 | * Enable or disable Voice over NR (VoNR) |
| 9296 | * @param subId the subscription ID that this action applies to. |
| 9297 | * @param enabled enable or disable VoNR. |
| 9298 | * @return operation result. |
| 9299 | */ |
| 9300 | @Override |
| 9301 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9302 | enforceModifyPermission(); |
| 9303 | final Phone phone = getPhone(subId); |
| 9304 | |
| 9305 | final long identity = Binder.clearCallingIdentity(); |
| 9306 | if (phone == null) { |
| 9307 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9308 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9309 | } |
| 9310 | |
| 9311 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9312 | try { |
| 9313 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9314 | workSource); |
| 9315 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9316 | |
| 9317 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9318 | if (DBG) { |
| 9319 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9320 | } |
| 9321 | SubscriptionManager.setSubscriptionProperty( |
| 9322 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9323 | (enabled ? "1" : "0")); |
| 9324 | } |
| 9325 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9326 | return result; |
| 9327 | } finally { |
| 9328 | Binder.restoreCallingIdentity(identity); |
| 9329 | } |
| 9330 | } |
| 9331 | |
| 9332 | /** |
| 9333 | * Is voice over NR enabled |
| 9334 | * @return true if VoNR is enabled else false |
| 9335 | */ |
| 9336 | @Override |
| 9337 | public boolean isVoNrEnabled(int subId) { |
| 9338 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9339 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9340 | final long identity = Binder.clearCallingIdentity(); |
| 9341 | try { |
| 9342 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9343 | null, subId, workSource); |
| 9344 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9345 | return isEnabled; |
| 9346 | } finally { |
| 9347 | Binder.restoreCallingIdentity(identity); |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9352 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9353 | * network status based on which carrier apps could apply actions accordingly, |
| 9354 | * enable/disable default url handler for example. |
| 9355 | * |
| 9356 | * @param subId the subscription ID that this action applies to. |
| 9357 | * @param report control start/stop reporting the default network status. |
| 9358 | * {@hide} |
| 9359 | */ |
| 9360 | @Override |
| 9361 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9362 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9363 | |
| 9364 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9365 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9366 | "carrierActionReportDefaultNetworkStatus"); |
| 9367 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9368 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9369 | |
| 9370 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9371 | if (phone == null) { |
| 9372 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9373 | return; |
| 9374 | } |
| 9375 | try { |
| 9376 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9377 | } catch (Exception e) { |
| 9378 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9379 | } finally { |
| 9380 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9381 | } |
| 9382 | } |
| 9383 | |
| 9384 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9385 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9386 | * @param subId the subscription ID that this action applies to. |
| 9387 | * {@hide} |
| 9388 | */ |
| 9389 | @Override |
| 9390 | public void carrierActionResetAll(int subId) { |
| 9391 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9392 | |
| 9393 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9394 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9395 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9396 | final Phone phone = getPhone(subId); |
| 9397 | if (phone == null) { |
| 9398 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9399 | return; |
| 9400 | } |
| 9401 | try { |
| 9402 | phone.carrierActionResetAll(); |
| 9403 | } catch (Exception e) { |
| 9404 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9405 | } |
| 9406 | } |
| 9407 | |
| 9408 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9409 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9410 | * bug report is being generated. |
| 9411 | */ |
| 9412 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9413 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9414 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9415 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9416 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9417 | + Binder.getCallingPid() |
| 9418 | + ", uid=" + Binder.getCallingUid() |
| 9419 | + "without permission " |
| 9420 | + android.Manifest.permission.DUMP); |
| 9421 | return; |
| 9422 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9423 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9424 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9425 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9426 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9427 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9428 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9429 | @NonNull String[] args) { |
| 9430 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9431 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9432 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9433 | } |
| 9434 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9435 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9436 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9437 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9438 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9439 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9440 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9441 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9442 | */ |
| 9443 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9444 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9445 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9446 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9447 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9448 | try { |
| 9449 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9450 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9451 | } catch (SecurityException se) { |
| 9452 | enforceModifyPermission(); |
| 9453 | } |
| 9454 | } else { |
| 9455 | enforceModifyPermission(); |
| 9456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9457 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9458 | enforceTelephonyFeatureWithException(callingPackage, |
| 9459 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9460 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9461 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9462 | final long identity = Binder.clearCallingIdentity(); |
| 9463 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9464 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9465 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 9466 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
| 9467 | callingUid, callingPackage, null, null); |
| 9468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9469 | Phone phone = getPhone(subId); |
| 9470 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9471 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9472 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9473 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9474 | phone.getDataSettingsManager().setDataEnabled( |
| 9475 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9476 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9477 | } |
| 9478 | } finally { |
| 9479 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9480 | } |
| 9481 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9482 | |
| 9483 | /** |
| 9484 | * Get Client request stats |
| 9485 | * @return List of Client Request Stats |
| 9486 | * @hide |
| 9487 | */ |
| 9488 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9489 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9490 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9491 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9492 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9493 | return null; |
| 9494 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9495 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9496 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9497 | final long identity = Binder.clearCallingIdentity(); |
| 9498 | try { |
| 9499 | if (phone != null) { |
| 9500 | return phone.getClientRequestStats(); |
| 9501 | } |
| 9502 | |
| 9503 | return null; |
| 9504 | } finally { |
| 9505 | Binder.restoreCallingIdentity(identity); |
| 9506 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9507 | } |
| 9508 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9509 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9510 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9511 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9512 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9513 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9514 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9515 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9516 | // commands that plumb through the RIL as root, like so: |
| 9517 | // $ adb root |
| 9518 | // $ adb shell cmd phone ... |
| 9519 | packageName = "root"; |
| 9520 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9521 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9522 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9523 | |
| 9524 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9525 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9526 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9527 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9528 | * @param state State of SIM (power down, power up, pass through) |
| 9529 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9530 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9531 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9532 | * |
| 9533 | **/ |
| 9534 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9535 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9536 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9537 | |
| 9538 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9539 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9540 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9541 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9542 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9543 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9544 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9545 | final long identity = Binder.clearCallingIdentity(); |
| 9546 | try { |
| 9547 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9548 | phone.setSimPowerState(state, null, workSource); |
| 9549 | } |
| 9550 | } finally { |
| 9551 | Binder.restoreCallingIdentity(identity); |
| 9552 | } |
| 9553 | } |
| 9554 | |
| 9555 | /** |
| 9556 | * Set SIM card power state. |
| 9557 | * |
| 9558 | * @param slotIndex SIM slot id. |
| 9559 | * @param state State of SIM (power down, power up, pass through) |
| 9560 | * @param callback callback to trigger after success or failure |
| 9561 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9562 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9563 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9564 | * |
| 9565 | **/ |
| 9566 | @Override |
| 9567 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9568 | IIntegerConsumer callback) { |
| 9569 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9570 | |
| 9571 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9572 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9573 | "setSimPowerStateForSlotWithCallback"); |
| 9574 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9575 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9576 | |
| 9577 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9578 | |
| 9579 | final long identity = Binder.clearCallingIdentity(); |
| 9580 | try { |
| 9581 | if (phone != null) { |
| 9582 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9583 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9584 | } |
| 9585 | } finally { |
| 9586 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9587 | } |
| 9588 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9589 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9590 | private boolean isUssdApiAllowed(int subId) { |
| 9591 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9592 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9593 | if (configManager == null) { |
| 9594 | return false; |
| 9595 | } |
| 9596 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9597 | if (pb == null) { |
| 9598 | return false; |
| 9599 | } |
| 9600 | return pb.getBoolean( |
| 9601 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9602 | } |
| 9603 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9604 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9605 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9606 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9607 | * @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] | 9608 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9609 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9610 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9611 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9612 | |
| 9613 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9614 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9615 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9616 | final long identity = Binder.clearCallingIdentity(); |
| 9617 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9618 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9619 | } finally { |
| 9620 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9621 | } |
| 9622 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9623 | |
| 9624 | /** |
| 9625 | * Get the current signal strength information for the given subscription. |
| 9626 | * Because this information is not updated when the device is in a low power state |
| 9627 | * it should not be relied-upon to be current. |
| 9628 | * @param subId Subscription index |
| 9629 | * @return the most recent cached signal strength info from the modem |
| 9630 | */ |
| 9631 | @Override |
| 9632 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9633 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9634 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9636 | final long identity = Binder.clearCallingIdentity(); |
| 9637 | try { |
| 9638 | Phone p = getPhone(subId); |
| 9639 | if (p == null) { |
| 9640 | return null; |
| 9641 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9643 | return p.getSignalStrength(); |
| 9644 | } finally { |
| 9645 | Binder.restoreCallingIdentity(identity); |
| 9646 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9647 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9648 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9649 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9650 | * Get the current modem radio state for the given slot. |
| 9651 | * @param slotIndex slot index. |
| 9652 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9653 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9654 | * @return the current radio power state from the modem |
| 9655 | */ |
| 9656 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9657 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9658 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9659 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9660 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9661 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9662 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9663 | } |
| 9664 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9665 | enforceTelephonyFeatureWithException(callingPackage, |
| 9666 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9667 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9668 | final long identity = Binder.clearCallingIdentity(); |
| 9669 | try { |
| 9670 | return phone.getRadioPowerState(); |
| 9671 | } finally { |
| 9672 | Binder.restoreCallingIdentity(identity); |
| 9673 | } |
| 9674 | } |
| 9675 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9676 | } |
| 9677 | |
| 9678 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9679 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9680 | * |
| 9681 | * <p>Requires one of the following permissions: |
| 9682 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9683 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9684 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9685 | * privileges. |
| 9686 | * |
| 9687 | * @param subId subscription id |
| 9688 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9689 | * {@code false}. |
| 9690 | */ |
| 9691 | @Override |
| 9692 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9693 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9694 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9695 | try { |
| 9696 | mApp.enforceCallingOrSelfPermission( |
| 9697 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9698 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9699 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9700 | mApp.enforceCallingOrSelfPermission( |
| 9701 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9702 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9703 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9704 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9705 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9706 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9707 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9708 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9709 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9710 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9711 | boolean isEnabled = false; |
| 9712 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9713 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9714 | Phone phone = getPhone(subId); |
| 9715 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9716 | } finally { |
| 9717 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9718 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9719 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9720 | } |
| 9721 | |
| 9722 | |
| 9723 | /** |
| 9724 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9725 | * |
| 9726 | * <p> Requires permission: |
| 9727 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9728 | * privileges. |
| 9729 | * |
| 9730 | * @param subId subscription id |
| 9731 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9732 | */ |
| 9733 | @Override |
| 9734 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9736 | mApp, subId, "setDataRoamingEnabled"); |
| 9737 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9738 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9739 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9740 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9741 | final long identity = Binder.clearCallingIdentity(); |
| 9742 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9743 | Phone phone = getPhone(subId); |
| 9744 | if (phone != null) { |
| 9745 | phone.setDataRoamingEnabled(isEnabled); |
| 9746 | } |
| 9747 | } finally { |
| 9748 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9749 | } |
| 9750 | } |
| 9751 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9752 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9753 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9754 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9755 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9756 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9757 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9758 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9759 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9760 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9761 | boolean isAllowed = true; |
| 9762 | final long identity = Binder.clearCallingIdentity(); |
| 9763 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9764 | Phone phone = getPhone(subId); |
| 9765 | if (phone != null) { |
| 9766 | isAllowed = phone.isCspPlmnEnabled(); |
| 9767 | } |
| 9768 | } finally { |
| 9769 | Binder.restoreCallingIdentity(identity); |
| 9770 | } |
| 9771 | return isAllowed; |
| 9772 | } |
| 9773 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9774 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9775 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9776 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9777 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9778 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9779 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9780 | if (phone == null) { |
| 9781 | return false; |
| 9782 | } |
| 9783 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9784 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9785 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9786 | } |
| 9787 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9788 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9789 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9790 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9791 | mApp.getSystemService(AppOpsManager.class) |
| 9792 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9793 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9794 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9795 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9796 | try { |
| 9797 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9798 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9799 | } catch (SecurityException e) { |
| 9800 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9801 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9802 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9803 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9804 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9805 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9806 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9807 | |
| 9808 | enforceTelephonyFeatureWithException(callingPackage, |
| 9809 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9810 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9811 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9812 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9813 | Binder.getCallingUid())) { |
| 9814 | isIccIdAccessRestricted = true; |
| 9815 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9816 | final long identity = Binder.clearCallingIdentity(); |
| 9817 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9818 | UiccController uiccController = UiccController.getInstance(); |
| 9819 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9820 | if (hasReadPermission) { |
| 9821 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9822 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9823 | |
| 9824 | // Remove private info if the caller doesn't have access |
| 9825 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9826 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9827 | //setting the value after compatibility check |
| 9828 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9829 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9830 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9831 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9832 | if (card == null) { |
| 9833 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9834 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9835 | continue; |
| 9836 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9837 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9838 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9839 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9840 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9841 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9842 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9843 | for (UiccPortInfo portInfo : portInfos) { |
| 9844 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9845 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9846 | if (port == null) { |
| 9847 | // assume no access if port is null |
| 9848 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9849 | continue; |
| 9850 | } |
| 9851 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9852 | uiccPortInfos.add(portInfo); |
| 9853 | } else { |
| 9854 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9855 | } |
| 9856 | } |
| 9857 | filteredInfos.add(new UiccCardInfo( |
| 9858 | cardInfo.isEuicc(), |
| 9859 | cardInfo.getCardId(), |
| 9860 | null, |
| 9861 | cardInfo.getPhysicalSlotIndex(), |
| 9862 | cardInfo.isRemovable(), |
| 9863 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9864 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9865 | } |
| 9866 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9867 | } finally { |
| 9868 | Binder.restoreCallingIdentity(identity); |
| 9869 | } |
| 9870 | } |
| 9871 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9872 | /** |
| 9873 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9874 | * generally private and require carrier privileges to view. |
| 9875 | * |
| 9876 | * @hide |
| 9877 | */ |
| 9878 | @NonNull |
| 9879 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9880 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9881 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9882 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9883 | } |
| 9884 | return new UiccCardInfo( |
| 9885 | cardInfo.isEuicc(), |
| 9886 | cardInfo.getCardId(), |
| 9887 | null, |
| 9888 | cardInfo.getPhysicalSlotIndex(), |
| 9889 | cardInfo.isRemovable(), |
| 9890 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9891 | portinfo |
| 9892 | ); |
| 9893 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9894 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9895 | /** |
| 9896 | * @hide |
| 9897 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9898 | * These values are generally private and require carrier privileges to view. |
| 9899 | */ |
| 9900 | @NonNull |
| 9901 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9902 | return new UiccPortInfo( |
| 9903 | UiccPortInfo.ICCID_REDACTED, |
| 9904 | portInfo.getPortIndex(), |
| 9905 | portInfo.getLogicalSlotIndex(), |
| 9906 | portInfo.isActive() |
| 9907 | ); |
| 9908 | } |
| 9909 | @Override |
| 9910 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9911 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9912 | mApp.getSystemService(AppOpsManager.class) |
| 9913 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9914 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9915 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9916 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9917 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9918 | // we are reading iccId which is PII data. |
| 9919 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9920 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9921 | enforceTelephonyFeatureWithException(callingPackage, |
| 9922 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9923 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9924 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9925 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9926 | Binder.getCallingUid())) { |
| 9927 | isLogicalSlotAccessRestricted = true; |
| 9928 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9929 | final long identity = Binder.clearCallingIdentity(); |
| 9930 | try { |
| 9931 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9932 | if (slots == null || slots.length == 0) { |
| 9933 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9934 | return null; |
| 9935 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9936 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9937 | for (int i = 0; i < slots.length; i++) { |
| 9938 | UiccSlot slot = slots[i]; |
| 9939 | if (slot == null) { |
| 9940 | continue; |
| 9941 | } |
| 9942 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9943 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9944 | UiccCard card = slot.getUiccCard(); |
| 9945 | if (card != null) { |
| 9946 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9947 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9948 | cardId = slot.getEid(); |
| 9949 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9950 | // If cardId is null, use iccId of default port as cardId. |
| 9951 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9952 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9953 | } |
| 9954 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9955 | if (cardId != null) { |
| 9956 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9957 | // if cardId is an EID, it's all digits so this is fine |
| 9958 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9959 | } |
| 9960 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9961 | int cardState = 0; |
| 9962 | switch (slot.getCardState()) { |
| 9963 | case CARDSTATE_ABSENT: |
| 9964 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9965 | break; |
| 9966 | case CARDSTATE_PRESENT: |
| 9967 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9968 | break; |
| 9969 | case CARDSTATE_ERROR: |
| 9970 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9971 | break; |
| 9972 | case CARDSTATE_RESTRICTED: |
| 9973 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9974 | break; |
| 9975 | default: |
| 9976 | break; |
| 9977 | |
| 9978 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9979 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9980 | int[] portIndexes = slot.getPortList(); |
| 9981 | for (int portIdx : portIndexes) { |
| 9982 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9983 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9984 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9985 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9987 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9988 | slot.isEuicc(), |
| 9989 | cardId, |
| 9990 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9991 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9992 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9993 | //setting the value after compatibility check |
| 9994 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9995 | } |
| 9996 | return infos; |
| 9997 | } finally { |
| 9998 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9999 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10000 | } |
| 10001 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10002 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10003 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10004 | boolean hasReadPermission) { |
| 10005 | String iccId = slot.getIccId(portIndex); |
| 10006 | if (hasReadPermission) { // if has read permission |
| 10007 | return iccId; |
| 10008 | } else { |
| 10009 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10010 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10011 | // if no read permission, checking carrier privilege access |
| 10012 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10013 | return iccId; |
| 10014 | } |
| 10015 | } |
| 10016 | } |
| 10017 | // No read permission or carrier privilege access. |
| 10018 | return UiccPortInfo.ICCID_REDACTED; |
| 10019 | } |
| 10020 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10021 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10022 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10023 | public boolean switchSlots(int[] physicalSlots) { |
| 10024 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10025 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10026 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10027 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10028 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10029 | final long identity = Binder.clearCallingIdentity(); |
| 10030 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10031 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10032 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10033 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10034 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10035 | physicalSlots[i], i)); |
| 10036 | } |
| 10037 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10038 | } finally { |
| 10039 | Binder.restoreCallingIdentity(identity); |
| 10040 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10041 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10042 | |
| 10043 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10044 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10045 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10046 | enforceModifyPermission(); |
| 10047 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10048 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10049 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10050 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10051 | final long identity = Binder.clearCallingIdentity(); |
| 10052 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10053 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10054 | } finally { |
| 10055 | Binder.restoreCallingIdentity(identity); |
| 10056 | } |
| 10057 | } |
| 10058 | |
| 10059 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10060 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10061 | enforceTelephonyFeatureWithException(callingPackage, |
| 10062 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10063 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10064 | final long identity = Binder.clearCallingIdentity(); |
| 10065 | try { |
| 10066 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10067 | } finally { |
| 10068 | Binder.restoreCallingIdentity(identity); |
| 10069 | } |
| 10070 | } |
| 10071 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10072 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10073 | * A test API to reload the UICC profile. |
| 10074 | * |
| 10075 | * <p>Requires that the calling app has permission |
| 10076 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10077 | * @hide |
| 10078 | */ |
| 10079 | @Override |
| 10080 | public void refreshUiccProfile(int subId) { |
| 10081 | enforceModifyPermission(); |
| 10082 | |
| 10083 | final long identity = Binder.clearCallingIdentity(); |
| 10084 | try { |
| 10085 | Phone phone = getPhone(subId); |
| 10086 | if (phone == null) { |
| 10087 | return; |
| 10088 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10089 | UiccPort uiccPort = phone.getUiccPort(); |
| 10090 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10091 | return; |
| 10092 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10093 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10094 | if (uiccProfile == null) { |
| 10095 | return; |
| 10096 | } |
| 10097 | uiccProfile.refresh(); |
| 10098 | } finally { |
| 10099 | Binder.restoreCallingIdentity(identity); |
| 10100 | } |
| 10101 | } |
| 10102 | |
| 10103 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10104 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10105 | */ |
| 10106 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10107 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10108 | } |
| 10109 | |
| 10110 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10111 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10112 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10113 | */ |
| 10114 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10115 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10116 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10117 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10118 | return list.get(phoneId); |
| 10119 | } |
| 10120 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10121 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10122 | |
| 10123 | @Override |
| 10124 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10125 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10126 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10127 | |
| 10128 | final long identity = Binder.clearCallingIdentity(); |
| 10129 | try { |
| 10130 | final Phone phone = getPhone(subId); |
| 10131 | if (phone == null) { |
| 10132 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10133 | return; |
| 10134 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10135 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10136 | if (cpt != null) { |
| 10137 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10138 | } |
| 10139 | // 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] | 10140 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10141 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10142 | if (carrierPrivilegeRules == null) { |
| 10143 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10144 | } else { |
| 10145 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10146 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10147 | } finally { |
| 10148 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10149 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10150 | } |
| 10151 | |
| 10152 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10153 | public void setCarrierServicePackageOverride( |
| 10154 | int subId, String carrierServicePackage, String callingPackage) { |
| 10155 | TelephonyPermissions.enforceShellOnly( |
| 10156 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10157 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10158 | final long identity = Binder.clearCallingIdentity(); |
| 10159 | try { |
| 10160 | final Phone phone = getPhone(subId); |
| 10161 | if (phone == null || phone.getSubId() != subId) { |
| 10162 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10163 | throw new IllegalArgumentException("No phone for subid"); |
| 10164 | } |
| 10165 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10166 | if (cpt == null) { |
| 10167 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10168 | throw new IllegalStateException("No CPT for phone"); |
| 10169 | } |
| 10170 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10171 | } finally { |
| 10172 | Binder.restoreCallingIdentity(identity); |
| 10173 | } |
| 10174 | } |
| 10175 | |
| 10176 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10177 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10178 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10179 | |
| 10180 | final long identity = Binder.clearCallingIdentity(); |
| 10181 | try { |
| 10182 | final Phone phone = getPhone(subId); |
| 10183 | if (phone == null) { |
| 10184 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10185 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10186 | } |
| 10187 | return phone.getCarrierIdListVersion(); |
| 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 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10192 | |
| 10193 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10194 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10195 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10196 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10197 | mApp, subId, callingPackage, callingFeatureId, |
| 10198 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10199 | return -1; |
| 10200 | } |
| 10201 | |
| 10202 | final long identity = Binder.clearCallingIdentity(); |
| 10203 | try { |
| 10204 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10205 | } finally { |
| 10206 | Binder.restoreCallingIdentity(identity); |
| 10207 | } |
| 10208 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10209 | |
| 10210 | @Override |
| 10211 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10212 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10213 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10214 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10215 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10216 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10217 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10218 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10219 | final long identity = Binder.clearCallingIdentity(); |
| 10220 | try { |
| 10221 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10222 | } finally { |
| 10223 | Binder.restoreCallingIdentity(identity); |
| 10224 | } |
| 10225 | } |
| 10226 | |
| 10227 | @Override |
| 10228 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10229 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10230 | mApp, subId, "setCdmaRoamingMode"); |
| 10231 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10232 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10233 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10234 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10235 | final long identity = Binder.clearCallingIdentity(); |
| 10236 | try { |
| 10237 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10238 | } finally { |
| 10239 | Binder.restoreCallingIdentity(identity); |
| 10240 | } |
| 10241 | } |
| 10242 | |
| 10243 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10244 | public int getCdmaSubscriptionMode(int subId) { |
| 10245 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10246 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10247 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10248 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10249 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10250 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10251 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10252 | final long identity = Binder.clearCallingIdentity(); |
| 10253 | try { |
| 10254 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10255 | } finally { |
| 10256 | Binder.restoreCallingIdentity(identity); |
| 10257 | } |
| 10258 | } |
| 10259 | |
| 10260 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10261 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10262 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10263 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10264 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10265 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10266 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10267 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10268 | final long identity = Binder.clearCallingIdentity(); |
| 10269 | try { |
| 10270 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10271 | } finally { |
| 10272 | Binder.restoreCallingIdentity(identity); |
| 10273 | } |
| 10274 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10275 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10276 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10277 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10278 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10279 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10280 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10281 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10282 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10283 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10284 | |
| 10285 | enforceTelephonyFeatureWithException(callingPackage, |
| 10286 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10287 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10288 | final long identity = Binder.clearCallingIdentity(); |
| 10289 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10290 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10291 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10292 | if (phone.getEmergencyNumberTracker() != null |
| 10293 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10294 | emergencyNumberListInternal.put( |
| 10295 | phone.getSubId(), |
| 10296 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10297 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10298 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10299 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10300 | } finally { |
| 10301 | Binder.restoreCallingIdentity(identity); |
| 10302 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10303 | } |
| 10304 | |
| 10305 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10306 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10307 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10308 | if (!exactMatch) { |
| 10309 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10310 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10311 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10312 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10313 | |
| 10314 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10315 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10316 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10317 | final long identity = Binder.clearCallingIdentity(); |
| 10318 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10319 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10320 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10321 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10322 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10323 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10324 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10325 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10326 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10327 | } |
| 10328 | return false; |
| 10329 | } finally { |
| 10330 | Binder.restoreCallingIdentity(identity); |
| 10331 | } |
| 10332 | } |
| 10333 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10334 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10335 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10336 | */ |
| 10337 | @Override |
| 10338 | public void startEmergencyCallbackMode() { |
| 10339 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10340 | "startEmergencyCallbackMode"); |
| 10341 | enforceModifyPermission(); |
| 10342 | final long identity = Binder.clearCallingIdentity(); |
| 10343 | try { |
| 10344 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10345 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10346 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10347 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10348 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10349 | gsmCdmaPhone.obtainMessage( |
| 10350 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10351 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10352 | } |
| 10353 | } |
| 10354 | } finally { |
| 10355 | Binder.restoreCallingIdentity(identity); |
| 10356 | } |
| 10357 | } |
| 10358 | |
| 10359 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10360 | * Update emergency number list for test mode. |
| 10361 | */ |
| 10362 | @Override |
| 10363 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10364 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10365 | "updateEmergencyNumberListTestMode"); |
| 10366 | |
| 10367 | final long identity = Binder.clearCallingIdentity(); |
| 10368 | try { |
| 10369 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10370 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10371 | if (tracker != null) { |
| 10372 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10373 | } |
| 10374 | } |
| 10375 | } finally { |
| 10376 | Binder.restoreCallingIdentity(identity); |
| 10377 | } |
| 10378 | } |
| 10379 | |
| 10380 | /** |
| 10381 | * Get the full emergency number list for test mode. |
| 10382 | */ |
| 10383 | @Override |
| 10384 | public List<String> getEmergencyNumberListTestMode() { |
| 10385 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10386 | "getEmergencyNumberListTestMode"); |
| 10387 | |
| 10388 | final long identity = Binder.clearCallingIdentity(); |
| 10389 | try { |
| 10390 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10391 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10392 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10393 | if (tracker != null) { |
| 10394 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10395 | emergencyNumbers.add(num.getNumber()); |
| 10396 | } |
| 10397 | } |
| 10398 | } |
| 10399 | return new ArrayList<>(emergencyNumbers); |
| 10400 | } finally { |
| 10401 | Binder.restoreCallingIdentity(identity); |
| 10402 | } |
| 10403 | } |
| 10404 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10405 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10406 | public int getEmergencyNumberDbVersion(int subId) { |
| 10407 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10408 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10409 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10410 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10411 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10412 | final long identity = Binder.clearCallingIdentity(); |
| 10413 | try { |
| 10414 | final Phone phone = getPhone(subId); |
| 10415 | if (phone == null) { |
| 10416 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10417 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10418 | } |
| 10419 | return phone.getEmergencyNumberDbVersion(); |
| 10420 | } finally { |
| 10421 | Binder.restoreCallingIdentity(identity); |
| 10422 | } |
| 10423 | } |
| 10424 | |
| 10425 | @Override |
| 10426 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10427 | enforceModifyPermission(); |
| 10428 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10429 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10430 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10431 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10432 | final long identity = Binder.clearCallingIdentity(); |
| 10433 | try { |
| 10434 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10435 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10436 | if (tracker != null) { |
| 10437 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10438 | } |
| 10439 | } |
| 10440 | } finally { |
| 10441 | Binder.restoreCallingIdentity(identity); |
| 10442 | } |
| 10443 | } |
| 10444 | |
| 10445 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10446 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10447 | enforceActiveEmergencySessionPermission(); |
| 10448 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10449 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10450 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10451 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10452 | final long identity = Binder.clearCallingIdentity(); |
| 10453 | try { |
| 10454 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10455 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10456 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10457 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10458 | } |
| 10459 | } |
| 10460 | } finally { |
| 10461 | Binder.restoreCallingIdentity(identity); |
| 10462 | } |
| 10463 | } |
| 10464 | |
| 10465 | @Override |
| 10466 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10467 | enforceActiveEmergencySessionPermission(); |
| 10468 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10469 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10470 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10471 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10472 | final long identity = Binder.clearCallingIdentity(); |
| 10473 | try { |
| 10474 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10475 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10476 | if (tracker != null) { |
| 10477 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10478 | } |
| 10479 | } |
| 10480 | } finally { |
| 10481 | Binder.restoreCallingIdentity(identity); |
| 10482 | } |
| 10483 | } |
| 10484 | |
| 10485 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10486 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10487 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10488 | Phone phone = getPhone(subId); |
| 10489 | if (phone == null) { |
| 10490 | return null; |
| 10491 | } |
| 10492 | final long identity = Binder.clearCallingIdentity(); |
| 10493 | try { |
| 10494 | UiccProfile profile = UiccController.getInstance() |
| 10495 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10496 | if (profile != null) { |
| 10497 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10498 | } |
| 10499 | } finally { |
| 10500 | Binder.restoreCallingIdentity(identity); |
| 10501 | } |
| 10502 | return null; |
| 10503 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10504 | |
| 10505 | /** |
| 10506 | * Enable or disable a modem stack. |
| 10507 | */ |
| 10508 | @Override |
| 10509 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10510 | enforceModifyPermission(); |
| 10511 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10512 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10513 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10514 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10515 | final long identity = Binder.clearCallingIdentity(); |
| 10516 | try { |
| 10517 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10518 | if (phone == null) { |
| 10519 | return false; |
| 10520 | } else { |
| 10521 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10522 | } |
| 10523 | } finally { |
| 10524 | Binder.restoreCallingIdentity(identity); |
| 10525 | } |
| 10526 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10527 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10528 | /** |
| 10529 | * Whether a modem stack is enabled or not. |
| 10530 | */ |
| 10531 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10532 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10533 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10534 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10535 | if (phone == null) return false; |
| 10536 | |
| 10537 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10538 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10539 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10540 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10541 | } |
| 10542 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10543 | enforceTelephonyFeatureWithException(callingPackage, |
| 10544 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10545 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10546 | final long identity = Binder.clearCallingIdentity(); |
| 10547 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10548 | try { |
| 10549 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10550 | } catch (NoSuchElementException ex) { |
| 10551 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10552 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10553 | } finally { |
| 10554 | Binder.restoreCallingIdentity(identity); |
| 10555 | } |
| 10556 | } |
| 10557 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10558 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10559 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10560 | enforceModifyPermission(); |
| 10561 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10562 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10563 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10564 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10565 | final long identity = Binder.clearCallingIdentity(); |
| 10566 | try { |
| 10567 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10568 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10569 | .commit(); |
| 10570 | } finally { |
| 10571 | Binder.restoreCallingIdentity(identity); |
| 10572 | } |
| 10573 | } |
| 10574 | |
| 10575 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10576 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10577 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10578 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10579 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10580 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10581 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10582 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10583 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10584 | enforceTelephonyFeatureWithException(callingPackage, |
| 10585 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10586 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10587 | final long identity = Binder.clearCallingIdentity(); |
| 10588 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10589 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10590 | } finally { |
| 10591 | Binder.restoreCallingIdentity(identity); |
| 10592 | } |
| 10593 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10594 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10595 | @TelephonyManager.IsMultiSimSupportedResult |
| 10596 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10597 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10598 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10599 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10600 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10601 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10602 | } |
| 10603 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10604 | // supported by the modem, indicate that it is restricted. |
| 10605 | PhoneCapability staticCapability = |
| 10606 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10607 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10608 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10609 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10610 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10611 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10612 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10613 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10614 | } |
| 10615 | // Check if support of multiple SIMs is restricted by carrier |
| 10616 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10617 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10618 | } |
| 10619 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10620 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10621 | } |
| 10622 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10623 | /** |
| 10624 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10625 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10626 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10627 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10628 | * @param numOfSims number of active sims we want to switch to |
| 10629 | */ |
| 10630 | @Override |
| 10631 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10632 | if (numOfSims == 1) { |
| 10633 | enforceModifyPermission(); |
| 10634 | } else { |
| 10635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10636 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10637 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10638 | |
| 10639 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10640 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10641 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10642 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10643 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10644 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10645 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10646 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10647 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10648 | return; |
| 10649 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10650 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10651 | } finally { |
| 10652 | Binder.restoreCallingIdentity(identity); |
| 10653 | } |
| 10654 | } |
| 10655 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10656 | @Override |
| 10657 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10658 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10659 | |
| 10660 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10661 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10662 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10663 | Phone phone = getPhone(subId); |
| 10664 | if (phone == null) { |
| 10665 | return false; |
| 10666 | } |
| 10667 | final long identity = Binder.clearCallingIdentity(); |
| 10668 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10669 | UiccPort uiccPort = phone.getUiccPort(); |
| 10670 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10671 | return false; |
| 10672 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10673 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10674 | if (uiccProfile == null) { |
| 10675 | return false; |
| 10676 | } |
| 10677 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10678 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10679 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10680 | } |
| 10681 | return false; |
| 10682 | } finally { |
| 10683 | Binder.restoreCallingIdentity(identity); |
| 10684 | } |
| 10685 | } |
| 10686 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10687 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10688 | * Get whether making changes to modem configurations will trigger reboot. |
| 10689 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10690 | */ |
| 10691 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10692 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10693 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10694 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10695 | mApp, subId, callingPackage, callingFeatureId, |
| 10696 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10697 | return false; |
| 10698 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10699 | |
| 10700 | enforceTelephonyFeatureWithException(callingPackage, |
| 10701 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10702 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10703 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10704 | final long identity = Binder.clearCallingIdentity(); |
| 10705 | try { |
| 10706 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10707 | } finally { |
| 10708 | Binder.restoreCallingIdentity(identity); |
| 10709 | } |
| 10710 | } |
| 10711 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10712 | private void updateModemStateMetrics() { |
| 10713 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10714 | // TODO: check the state for each modem if the api is ready. |
| 10715 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10716 | } |
| 10717 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10718 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10719 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10720 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10721 | // Verify that the callingPackage belongs to the calling UID |
| 10722 | mApp.getSystemService(AppOpsManager.class) |
| 10723 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10724 | |
| 10725 | enforceTelephonyFeatureWithException(callingPackage, |
| 10726 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10727 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10728 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10729 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10730 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10731 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10732 | if (slotInfos != null) { |
| 10733 | for (int i = 0; i < slotInfos.length; i++) { |
| 10734 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10735 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10736 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10737 | portInfo.getLogicalSlotIndex())); |
| 10738 | } |
| 10739 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10740 | } |
| 10741 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10742 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10743 | } finally { |
| 10744 | Binder.restoreCallingIdentity(identity); |
| 10745 | } |
| 10746 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10747 | |
| 10748 | /** |
| 10749 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10750 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10751 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10752 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10753 | @Override |
| 10754 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10755 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10756 | } |
| 10757 | |
| 10758 | /** |
| 10759 | * Get the HAL Version of a specific service |
| 10760 | */ |
| 10761 | @Override |
| 10762 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10763 | Phone phone = getDefaultPhone(); |
| 10764 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10765 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10766 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10767 | return hv.major * 100 + hv.minor; |
| 10768 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10769 | |
| 10770 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10771 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10772 | * |
| 10773 | * @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] | 10774 | */ |
| 10775 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10776 | public @Nullable String getCurrentPackageName() { |
| 10777 | PackageManager pm = mApp.getPackageManager(); |
| 10778 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10779 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10780 | } |
| 10781 | |
| 10782 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10783 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10784 | * corresponding network requests on a subId. |
| 10785 | * |
| 10786 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10787 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10788 | * 2) APN is un-metered for this subscription, or |
| 10789 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10790 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10791 | * |
| 10792 | * @return whether data is allowed for a apn type. |
| 10793 | * |
| 10794 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10795 | */ |
| 10796 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10797 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10798 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10799 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10800 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10801 | enforceTelephonyFeatureWithException(callingPackage, |
| 10802 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10803 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10804 | // Now that all security checks passes, perform the operation as ourselves. |
| 10805 | final long identity = Binder.clearCallingIdentity(); |
| 10806 | try { |
| 10807 | Phone phone = getPhone(subId); |
| 10808 | if (phone == null) return false; |
| 10809 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10810 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10811 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10812 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10813 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10814 | phone.getServiceState().getDataRoaming()); |
| 10815 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10816 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10817 | } finally { |
| 10818 | Binder.restoreCallingIdentity(identity); |
| 10819 | } |
| 10820 | } |
| 10821 | |
| 10822 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10823 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10824 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10825 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10826 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10827 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10828 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10829 | // Now that all security checks passes, perform the operation as ourselves. |
| 10830 | final long identity = Binder.clearCallingIdentity(); |
| 10831 | try { |
| 10832 | Phone phone = getPhone(subId); |
| 10833 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10834 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10835 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10836 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10837 | } finally { |
| 10838 | Binder.restoreCallingIdentity(identity); |
| 10839 | } |
| 10840 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10841 | |
| 10842 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10843 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10844 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10845 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10846 | |
| 10847 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10848 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10849 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10850 | long token = Binder.clearCallingIdentity(); |
| 10851 | try { |
| 10852 | Phone phone = getPhone(subscriptionId); |
| 10853 | if (phone == null) { |
| 10854 | try { |
| 10855 | if (resultCallback != null) { |
| 10856 | resultCallback.accept(false); |
| 10857 | } |
| 10858 | } catch (RemoteException e) { |
| 10859 | // ignore |
| 10860 | } |
| 10861 | return; |
| 10862 | } |
| 10863 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10864 | Pair.create(specifiers, (x) -> { |
| 10865 | try { |
| 10866 | if (resultCallback != null) { |
| 10867 | resultCallback.accept(x); |
| 10868 | } |
| 10869 | } catch (RemoteException e) { |
| 10870 | // ignore |
| 10871 | } |
| 10872 | }); |
| 10873 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10874 | } finally { |
| 10875 | Binder.restoreCallingIdentity(token); |
| 10876 | } |
| 10877 | } |
| 10878 | |
| 10879 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10880 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10881 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10882 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10883 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10884 | |
| 10885 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10886 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10887 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10888 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10889 | final long identity = Binder.clearCallingIdentity(); |
| 10890 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10891 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10892 | if (result instanceof IllegalStateException) { |
| 10893 | throw (IllegalStateException) result; |
| 10894 | } |
| 10895 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10896 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10897 | return specifiers; |
| 10898 | } finally { |
| 10899 | Binder.restoreCallingIdentity(identity); |
| 10900 | } |
| 10901 | } |
| 10902 | |
| 10903 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10904 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10905 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10906 | |
| 10907 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10908 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10909 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10910 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10911 | } |
| 10912 | |
| 10913 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10914 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10915 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10916 | if (callingPackage == null) { |
| 10917 | callingPackage = getCurrentPackageName(); |
| 10918 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10919 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10920 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10921 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10922 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10923 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10924 | } |
| 10925 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10926 | Intent intent = new Intent(); |
| 10927 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10928 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10929 | // Bring up choose default SMS subscription dialog right now |
| 10930 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10931 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10932 | mApp.startActivity(intent); |
| 10933 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10934 | |
| 10935 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10936 | public void showSwitchToManagedProfileDialog() { |
| 10937 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10938 | try { |
| 10939 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10940 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10941 | // for work telephony. |
| 10942 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10943 | intent.setData(Uri.parse("smsto:")); |
| 10944 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10945 | mApp.startActivity(intent); |
| 10946 | } catch (ActivityNotFoundException e) { |
| 10947 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10948 | Intent intent = new Intent(); |
| 10949 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10950 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10951 | mApp.startActivity(intent); |
| 10952 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10953 | } |
| 10954 | |
| 10955 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10956 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10957 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10958 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 10959 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10960 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10961 | final long identity = Binder.clearCallingIdentity(); |
| 10962 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10963 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10964 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10965 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10966 | return carrierUAProfUrl; |
| 10967 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10968 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10969 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10970 | } finally { |
| 10971 | Binder.restoreCallingIdentity(identity); |
| 10972 | } |
| 10973 | } |
| 10974 | |
| 10975 | @Override |
| 10976 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10977 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10978 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 10979 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10980 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10981 | final long identity = Binder.clearCallingIdentity(); |
| 10982 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10983 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10984 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10985 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10986 | return carrierUserAgent; |
| 10987 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10988 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10989 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10990 | } finally { |
| 10991 | Binder.restoreCallingIdentity(identity); |
| 10992 | } |
| 10993 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10994 | |
| 10995 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10996 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10997 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10998 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10999 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11000 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11001 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11002 | final long identity = Binder.clearCallingIdentity(); |
| 11003 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11004 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11005 | if (phone == null) return false; |
| 11006 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11007 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11008 | } finally { |
| 11009 | Binder.restoreCallingIdentity(identity); |
| 11010 | } |
| 11011 | } |
| 11012 | |
| 11013 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11014 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11015 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11016 | enforceModifyPermission(); |
| 11017 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11018 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11019 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11020 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11021 | final long identity = Binder.clearCallingIdentity(); |
| 11022 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11023 | Phone phone = getPhone(subscriptionId); |
| 11024 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11025 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11026 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11027 | } finally { |
| 11028 | Binder.restoreCallingIdentity(identity); |
| 11029 | } |
| 11030 | } |
| 11031 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11032 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11033 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11034 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11035 | * otherwise. |
| 11036 | */ |
| 11037 | @Override |
| 11038 | public void setCepEnabled(boolean isCepEnabled) { |
| 11039 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11040 | |
| 11041 | final long identity = Binder.clearCallingIdentity(); |
| 11042 | try { |
| 11043 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11044 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11045 | Phone defaultPhone = phone.getImsPhone(); |
| 11046 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11047 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11048 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11049 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11050 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11051 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11052 | + imsPhone.getMsisdn()); |
| 11053 | } |
| 11054 | } |
| 11055 | } finally { |
| 11056 | Binder.restoreCallingIdentity(identity); |
| 11057 | } |
| 11058 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11059 | |
| 11060 | /** |
| 11061 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11062 | * |
| 11063 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11064 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11065 | * before being read. |
| 11066 | */ |
| 11067 | @Override |
| 11068 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11069 | isCompressed) { |
| 11070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11071 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11072 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11073 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11074 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11075 | |
| 11076 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11077 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11078 | Binder.getCallingUserHandle())) { |
| 11079 | if (!isImsAvailableOnDevice()) { |
| 11080 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11081 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11082 | throw new IllegalStateException("IMS not available on device."); |
| 11083 | } |
| 11084 | } else { |
| 11085 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11086 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11087 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11088 | } |
| 11089 | |
| 11090 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11091 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11092 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11093 | } finally { |
| 11094 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11095 | } |
| 11096 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11097 | |
| 11098 | @Override |
| 11099 | public boolean isIccLockEnabled(int subId) { |
| 11100 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11101 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11102 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11103 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11104 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11105 | // Now that all security checks passes, perform the operation as ourselves. |
| 11106 | final long identity = Binder.clearCallingIdentity(); |
| 11107 | try { |
| 11108 | Phone phone = getPhone(subId); |
| 11109 | if (phone != null && phone.getIccCard() != null) { |
| 11110 | return phone.getIccCard().getIccLockEnabled(); |
| 11111 | } else { |
| 11112 | return false; |
| 11113 | } |
| 11114 | } finally { |
| 11115 | Binder.restoreCallingIdentity(identity); |
| 11116 | } |
| 11117 | } |
| 11118 | |
| 11119 | /** |
| 11120 | * Set the ICC pin lock enabled or disabled. |
| 11121 | * |
| 11122 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11123 | * three cases: |
| 11124 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11125 | * successfully. |
| 11126 | * - Positive number and zero for remaining password attempts. |
| 11127 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11128 | * |
| 11129 | */ |
| 11130 | @Override |
| 11131 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11132 | enforceModifyPermission(); |
| 11133 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11134 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11135 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11136 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11137 | Phone phone = getPhone(subId); |
| 11138 | if (phone == null) { |
| 11139 | return 0; |
| 11140 | } |
| 11141 | // Now that all security checks passes, perform the operation as ourselves. |
| 11142 | final long identity = Binder.clearCallingIdentity(); |
| 11143 | try { |
| 11144 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11145 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11146 | return attemptsRemaining; |
| 11147 | |
| 11148 | } catch (Exception e) { |
| 11149 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11150 | } finally { |
| 11151 | Binder.restoreCallingIdentity(identity); |
| 11152 | } |
| 11153 | return 0; |
| 11154 | } |
| 11155 | |
| 11156 | /** |
| 11157 | * Change the ICC password used in ICC pin lock. |
| 11158 | * |
| 11159 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11160 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11161 | * - Positive number and zero for remaining password attempts. |
| 11162 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11163 | * |
| 11164 | */ |
| 11165 | @Override |
| 11166 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11167 | enforceModifyPermission(); |
| 11168 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11169 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11170 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11171 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11172 | Phone phone = getPhone(subId); |
| 11173 | if (phone == null) { |
| 11174 | return 0; |
| 11175 | } |
| 11176 | // Now that all security checks passes, perform the operation as ourselves. |
| 11177 | final long identity = Binder.clearCallingIdentity(); |
| 11178 | try { |
| 11179 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11180 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11181 | return attemptsRemaining; |
| 11182 | |
| 11183 | } catch (Exception e) { |
| 11184 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11185 | } finally { |
| 11186 | Binder.restoreCallingIdentity(identity); |
| 11187 | } |
| 11188 | return 0; |
| 11189 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11190 | |
| 11191 | /** |
| 11192 | * Request for receiving user activity notification |
| 11193 | */ |
| 11194 | @Override |
| 11195 | public void requestUserActivityNotification() { |
| 11196 | if (!mNotifyUserActivity.get() |
| 11197 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11198 | mNotifyUserActivity.set(true); |
| 11199 | } |
| 11200 | } |
| 11201 | |
| 11202 | /** |
| 11203 | * Called when userActivity is signalled in the power manager. |
| 11204 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11205 | */ |
| 11206 | @Override |
| 11207 | public void userActivity() { |
| 11208 | // *************************************** |
| 11209 | // * Inherited from PhoneWindowManager * |
| 11210 | // *************************************** |
| 11211 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11212 | // WITH ITS LOCKS HELD. |
| 11213 | // |
| 11214 | // This code must be VERY careful about the locks |
| 11215 | // it acquires. |
| 11216 | // In fact, the current code acquires way too many, |
| 11217 | // and probably has lurking deadlocks. |
| 11218 | |
| 11219 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11220 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11221 | } |
| 11222 | |
| 11223 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11224 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11225 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11226 | } |
| 11227 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11228 | |
| 11229 | @Override |
| 11230 | public boolean canConnectTo5GInDsdsMode() { |
| 11231 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11232 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11233 | |
| 11234 | @Override |
| 11235 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11236 | String callingFeatureId) { |
| 11237 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11238 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11239 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11240 | } |
| 11241 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11242 | enforceTelephonyFeatureWithException(callingPackage, |
| 11243 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11244 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11245 | Phone phone = getPhone(subId); |
| 11246 | if (phone == null) { |
| 11247 | throw new RuntimeException("phone is not available"); |
| 11248 | } |
| 11249 | // Now that all security checks passes, perform the operation as ourselves. |
| 11250 | final long identity = Binder.clearCallingIdentity(); |
| 11251 | try { |
| 11252 | return phone.getEquivalentHomePlmns(); |
| 11253 | } finally { |
| 11254 | Binder.restoreCallingIdentity(identity); |
| 11255 | } |
| 11256 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11257 | |
| 11258 | @Override |
| 11259 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11260 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11261 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11262 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11263 | "isRadioInterfaceCapabilitySupported"); |
| 11264 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11265 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11266 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11267 | if (radioInterfaceCapabilities == null) { |
| 11268 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11269 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11270 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11271 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11272 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11273 | @Override |
| 11274 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11275 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11276 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11277 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11278 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11279 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11280 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11281 | |
| 11282 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11283 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11284 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11285 | if (DBG) { |
| 11286 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11287 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11288 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11289 | } |
| 11290 | |
| 11291 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11292 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11293 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11294 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11295 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11296 | if (callback != null) { |
| 11297 | try { |
| 11298 | callback.onAuthenticationFailure( |
| 11299 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11300 | } catch (RemoteException exception) { |
| 11301 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11302 | } |
| 11303 | return; |
| 11304 | } |
| 11305 | } |
| 11306 | |
| 11307 | final long token = Binder.clearCallingIdentity(); |
| 11308 | try { |
| 11309 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11310 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11311 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11312 | } finally { |
| 11313 | Binder.restoreCallingIdentity(token); |
| 11314 | } |
| 11315 | } |
| 11316 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11317 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11318 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11319 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11320 | * requested radio power state will actually be set. See {@link |
| 11321 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11322 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11323 | * @param enable {@code true} if trying to turn radio on. |
| 11324 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11325 | * false}. |
| 11326 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11327 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11328 | boolean isPhoneAvailable = false; |
| 11329 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11330 | Phone phone = PhoneFactory.getPhone(i); |
| 11331 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11332 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11333 | isPhoneAvailable = true; |
| 11334 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11335 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11336 | |
| 11337 | // return true if successfully informed the phone object about the thermal radio power |
| 11338 | // request. |
| 11339 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11340 | } |
| 11341 | |
| 11342 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11343 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11344 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11345 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11346 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11347 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11348 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11349 | } |
| 11350 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11351 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11352 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11353 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11354 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11355 | } |
| 11356 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11357 | setDataEnabledForReason( |
| 11358 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11359 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11360 | if (isDataThrottlingSupported) { |
| 11361 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11362 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11363 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11364 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11365 | } else if (thermalMitigationResult |
| 11366 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11367 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11368 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11369 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11370 | } |
| 11371 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11372 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11373 | |
| 11374 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11375 | } |
| 11376 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11377 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11378 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11379 | for (String pckg : context.getResources() |
| 11380 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11381 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11382 | } |
| 11383 | } |
| 11384 | |
| 11385 | return sThermalMitigationAllowlistedPackages; |
| 11386 | } |
| 11387 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11388 | private boolean isAnyPhoneInEmergencyState() { |
| 11389 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11390 | if (tm.isInEmergencyCall()) { |
| 11391 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11392 | return true; |
| 11393 | } |
| 11394 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11395 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11396 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11397 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11398 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11399 | return true; |
| 11400 | } |
| 11401 | } |
| 11402 | |
| 11403 | return false; |
| 11404 | } |
| 11405 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11406 | /** |
| 11407 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11408 | * @param packageName name of package to be allowlisted |
| 11409 | * @param context |
| 11410 | */ |
| 11411 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11412 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11413 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11414 | } |
| 11415 | |
| 11416 | /** |
| 11417 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11418 | * @param packageName name of package to remove from allowlist |
| 11419 | * @param context |
| 11420 | */ |
| 11421 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11422 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11423 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11424 | } |
| 11425 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11426 | /** |
| 11427 | * Thermal mitigation request to control functionalities at modem. |
| 11428 | * |
| 11429 | * @param subId the id of the subscription. |
| 11430 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11431 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11432 | * |
| 11433 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11434 | */ |
| 11435 | @Override |
| 11436 | @ThermalMitigationResult |
| 11437 | public int sendThermalMitigationRequest( |
| 11438 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11439 | ThermalMitigationRequest thermalMitigationRequest, |
| 11440 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11441 | enforceModifyPermission(); |
| 11442 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11443 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11444 | |
| 11445 | enforceTelephonyFeatureWithException(callingPackage, |
| 11446 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11447 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11448 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11449 | .contains(callingPackage)) { |
| 11450 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11451 | + "calling package: " + callingPackage); |
| 11452 | } |
| 11453 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11454 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11455 | final long identity = Binder.clearCallingIdentity(); |
| 11456 | |
| 11457 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11458 | try { |
| 11459 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11460 | switch (thermalMitigationAction) { |
| 11461 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11462 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11463 | handleDataThrottlingRequest(subId, |
| 11464 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11465 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11466 | break; |
| 11467 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11468 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11469 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11470 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11471 | } |
| 11472 | |
| 11473 | // Ensure that radio is on. If not able to power on due to phone being |
| 11474 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11475 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11476 | thermalMitigationResult = |
| 11477 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11478 | break; |
| 11479 | } |
| 11480 | |
| 11481 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11482 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11483 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11484 | break; |
| 11485 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11486 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11487 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11488 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11489 | } |
| 11490 | |
| 11491 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11492 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11493 | Phone phone = getPhone(subId); |
| 11494 | if (phone == null) { |
| 11495 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11496 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11497 | break; |
| 11498 | } |
| 11499 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11500 | TelephonyConnectionService service = |
| 11501 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11502 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11503 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11504 | thermalMitigationResult = |
| 11505 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11506 | break; |
| 11507 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11508 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11509 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11510 | break; |
| 11511 | } |
| 11512 | } else { |
| 11513 | thermalMitigationResult = |
| 11514 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11515 | break; |
| 11516 | } |
| 11517 | |
| 11518 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11519 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11520 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11521 | thermalMitigationResult = |
| 11522 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11523 | break; |
| 11524 | } |
| 11525 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11526 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11527 | break; |
| 11528 | default: |
| 11529 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11530 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11531 | } |
| 11532 | } catch (IllegalArgumentException e) { |
| 11533 | throw e; |
| 11534 | } catch (Exception e) { |
| 11535 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11536 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11537 | } finally { |
| 11538 | Binder.restoreCallingIdentity(identity); |
| 11539 | } |
| 11540 | |
| 11541 | if (DBG) { |
| 11542 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11543 | + thermalMitigationResult); |
| 11544 | } |
| 11545 | |
| 11546 | return thermalMitigationResult; |
| 11547 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11548 | |
| 11549 | /** |
| 11550 | * Set the GbaService Package Name that Telephony will bind to. |
| 11551 | * |
| 11552 | * @param subId The sim that the GbaService is associated with. |
| 11553 | * @param packageName The name of the package to be replaced with. |
| 11554 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11555 | */ |
| 11556 | @Override |
| 11557 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11558 | enforceModifyPermission(); |
| 11559 | |
| 11560 | final long identity = Binder.clearCallingIdentity(); |
| 11561 | try { |
| 11562 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11563 | } finally { |
| 11564 | Binder.restoreCallingIdentity(identity); |
| 11565 | } |
| 11566 | } |
| 11567 | |
| 11568 | /** |
| 11569 | * Return the package name of the currently bound GbaService. |
| 11570 | * |
| 11571 | * @param subId The sim that the GbaService is associated with. |
| 11572 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11573 | */ |
| 11574 | @Override |
| 11575 | public String getBoundGbaService(int subId) { |
| 11576 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11577 | |
| 11578 | final long identity = Binder.clearCallingIdentity(); |
| 11579 | try { |
| 11580 | return getGbaManager(subId).getServicePackage(); |
| 11581 | } finally { |
| 11582 | Binder.restoreCallingIdentity(identity); |
| 11583 | } |
| 11584 | } |
| 11585 | |
| 11586 | /** |
| 11587 | * Set the release time for telephony to unbind GbaService. |
| 11588 | * |
| 11589 | * @param subId The sim that the GbaService is associated with. |
| 11590 | * @param interval The release time to unbind GbaService by millisecond. |
| 11591 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11592 | */ |
| 11593 | @Override |
| 11594 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11595 | enforceModifyPermission(); |
| 11596 | |
| 11597 | final long identity = Binder.clearCallingIdentity(); |
| 11598 | try { |
| 11599 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11600 | } finally { |
| 11601 | Binder.restoreCallingIdentity(identity); |
| 11602 | } |
| 11603 | } |
| 11604 | |
| 11605 | /** |
| 11606 | * Return the release time for telephony to unbind GbaService. |
| 11607 | * |
| 11608 | * @param subId The sim that the GbaService is associated with. |
| 11609 | * @return The release time to unbind GbaService by millisecond. |
| 11610 | */ |
| 11611 | @Override |
| 11612 | public int getGbaReleaseTime(int subId) { |
| 11613 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11614 | |
| 11615 | final long identity = Binder.clearCallingIdentity(); |
| 11616 | try { |
| 11617 | return getGbaManager(subId).getReleaseTime(); |
| 11618 | } finally { |
| 11619 | Binder.restoreCallingIdentity(identity); |
| 11620 | } |
| 11621 | } |
| 11622 | |
| 11623 | private GbaManager getGbaManager(int subId) { |
| 11624 | GbaManager instance = GbaManager.getInstance(subId); |
| 11625 | if (instance == null) { |
| 11626 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11627 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11628 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11629 | } |
| 11630 | return instance; |
| 11631 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11632 | |
| 11633 | /** |
| 11634 | * indicate whether the device and the carrier can support |
| 11635 | * RCS VoLTE single registration. |
| 11636 | */ |
| 11637 | @Override |
| 11638 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11639 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11640 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11641 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11642 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11643 | |
| 11644 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11645 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11646 | } |
| 11647 | |
| 11648 | final long identity = Binder.clearCallingIdentity(); |
| 11649 | try { |
| 11650 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11651 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11652 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11653 | if (isCapable != null) { |
| 11654 | return isCapable; |
| 11655 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11656 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11657 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11658 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11659 | } finally { |
| 11660 | Binder.restoreCallingIdentity(identity); |
| 11661 | } |
| 11662 | } |
| 11663 | |
| 11664 | /** |
| 11665 | * Register RCS provisioning callback. |
| 11666 | */ |
| 11667 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11668 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11669 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11670 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11671 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11672 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11673 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11674 | |
| 11675 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11676 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11677 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11678 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11679 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11680 | Binder.getCallingUserHandle())) { |
| 11681 | if (!isImsAvailableOnDevice()) { |
| 11682 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11683 | "IMS not available on device."); |
| 11684 | } |
| 11685 | } else { |
| 11686 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11687 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11688 | } |
| 11689 | |
| 11690 | final long identity = Binder.clearCallingIdentity(); |
| 11691 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11692 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11693 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11694 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11695 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11696 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11697 | } finally { |
| 11698 | Binder.restoreCallingIdentity(identity); |
| 11699 | } |
| 11700 | } |
| 11701 | |
| 11702 | /** |
| 11703 | * Unregister RCS provisioning callback. |
| 11704 | */ |
| 11705 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11706 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11707 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11708 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11709 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11710 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11711 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11712 | |
| 11713 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11714 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11715 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11716 | |
| 11717 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11718 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11719 | Binder.getCallingUserHandle())) { |
| 11720 | if (!isImsAvailableOnDevice()) { |
| 11721 | // operation failed silently |
| 11722 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11723 | return; |
| 11724 | } |
| 11725 | } else { |
| 11726 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11727 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11728 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11729 | } |
| 11730 | |
| 11731 | final long identity = Binder.clearCallingIdentity(); |
| 11732 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11733 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11734 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11735 | } finally { |
| 11736 | Binder.restoreCallingIdentity(identity); |
| 11737 | } |
| 11738 | } |
| 11739 | |
| 11740 | /** |
| 11741 | * trigger RCS reconfiguration. |
| 11742 | */ |
| 11743 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11744 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11745 | "triggerRcsReconfiguration", |
| 11746 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11747 | |
| 11748 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11749 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11750 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11751 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11752 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11753 | Binder.getCallingUserHandle())) { |
| 11754 | if (!isImsAvailableOnDevice()) { |
| 11755 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11756 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11757 | throw new IllegalStateException("IMS not available on device."); |
| 11758 | } |
| 11759 | } else { |
| 11760 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11761 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11762 | } |
| 11763 | |
| 11764 | final long identity = Binder.clearCallingIdentity(); |
| 11765 | try { |
| 11766 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11767 | } finally { |
| 11768 | Binder.restoreCallingIdentity(identity); |
| 11769 | } |
| 11770 | } |
| 11771 | |
| 11772 | /** |
| 11773 | * Provide the client configuration parameters of the RCS application. |
| 11774 | */ |
| 11775 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11776 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11777 | "setRcsClientConfiguration", |
| 11778 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11779 | |
| 11780 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11781 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11782 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11783 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11784 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11785 | Binder.getCallingUserHandle())) { |
| 11786 | if (!isImsAvailableOnDevice()) { |
| 11787 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11788 | "IMS not available on device."); |
| 11789 | } |
| 11790 | } else { |
| 11791 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11792 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11793 | } |
| 11794 | |
| 11795 | final long identity = Binder.clearCallingIdentity(); |
| 11796 | |
| 11797 | try { |
| 11798 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11799 | if (configBinder == null) { |
| 11800 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11801 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11802 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11803 | } else { |
| 11804 | configBinder.setRcsClientConfiguration(rcc); |
| 11805 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11806 | |
| 11807 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11808 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11809 | } catch (RemoteException e) { |
| 11810 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11811 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11812 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11813 | } finally { |
| 11814 | Binder.restoreCallingIdentity(identity); |
| 11815 | } |
| 11816 | } |
| 11817 | |
| 11818 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11819 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11820 | */ |
| 11821 | @Override |
| 11822 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11823 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11824 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11825 | |
| 11826 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11827 | } |
| 11828 | |
| 11829 | /** |
| 11830 | * Gets the test mode for RCS VoLTE single registration. |
| 11831 | */ |
| 11832 | @Override |
| 11833 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11834 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11835 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11836 | |
| 11837 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11838 | } |
| 11839 | |
| 11840 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11841 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11842 | */ |
| 11843 | @Override |
| 11844 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11845 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11846 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11847 | enforceModifyPermission(); |
| 11848 | |
| 11849 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11850 | : Boolean.parseBoolean(enabledStr); |
| 11851 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11852 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11853 | } |
| 11854 | |
| 11855 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11856 | * Sends a device to device communication message. Only usable via shell. |
| 11857 | * @param message message to send. |
| 11858 | * @param value message value. |
| 11859 | */ |
| 11860 | @Override |
| 11861 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11862 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11863 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11864 | enforceModifyPermission(); |
| 11865 | |
| 11866 | final long identity = Binder.clearCallingIdentity(); |
| 11867 | try { |
| 11868 | TelephonyConnectionService service = |
| 11869 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11870 | if (service == null) { |
| 11871 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11872 | return; |
| 11873 | } |
| 11874 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11875 | } finally { |
| 11876 | Binder.restoreCallingIdentity(identity); |
| 11877 | } |
| 11878 | } |
| 11879 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11880 | /** |
| 11881 | * Sets the specified device to device transport active. |
| 11882 | * @param transport The transport to set active. |
| 11883 | */ |
| 11884 | @Override |
| 11885 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11886 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11887 | "setActiveDeviceToDeviceTransport"); |
| 11888 | enforceModifyPermission(); |
| 11889 | |
| 11890 | final long identity = Binder.clearCallingIdentity(); |
| 11891 | try { |
| 11892 | TelephonyConnectionService service = |
| 11893 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11894 | if (service == null) { |
| 11895 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11896 | return; |
| 11897 | } |
| 11898 | service.setActiveDeviceToDeviceTransport(transport); |
| 11899 | } finally { |
| 11900 | Binder.restoreCallingIdentity(identity); |
| 11901 | } |
| 11902 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11903 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11904 | @Override |
| 11905 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11906 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11907 | "setDeviceToDeviceForceEnabled"); |
| 11908 | |
| 11909 | final long identity = Binder.clearCallingIdentity(); |
| 11910 | try { |
| 11911 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11912 | p -> { |
| 11913 | Phone thePhone = p.getImsPhone(); |
| 11914 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11915 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11916 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11917 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11918 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11919 | (ImsPhoneCallTracker) tracker; |
| 11920 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11921 | } |
| 11922 | } |
| 11923 | } |
| 11924 | ); |
| 11925 | } finally { |
| 11926 | Binder.restoreCallingIdentity(identity); |
| 11927 | } |
| 11928 | } |
| 11929 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11930 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11931 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11932 | */ |
| 11933 | @Override |
| 11934 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11935 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11936 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11937 | } |
| 11938 | |
| 11939 | /** |
| 11940 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11941 | */ |
| 11942 | @Override |
| 11943 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11944 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11945 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11946 | enforceModifyPermission(); |
| 11947 | |
| 11948 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11949 | : Boolean.parseBoolean(enabledStr); |
| 11950 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11951 | subId, enabled); |
| 11952 | } |
| 11953 | |
| 11954 | /** |
| 11955 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11956 | */ |
| 11957 | @Override |
| 11958 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11959 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11960 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11961 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11962 | |
| 11963 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11964 | * Overrides the ims feature validation result |
| 11965 | */ |
| 11966 | @Override |
| 11967 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11968 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11969 | "setImsFeatureValidationOverride"); |
| 11970 | |
| 11971 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11972 | : Boolean.parseBoolean(enabledStr); |
| 11973 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11974 | subId, enabled); |
| 11975 | } |
| 11976 | |
| 11977 | /** |
| 11978 | * Gets the ims feature validation override value |
| 11979 | */ |
| 11980 | @Override |
| 11981 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11982 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11983 | "getImsFeatureValidationOverride"); |
| 11984 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11985 | } |
| 11986 | |
| 11987 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11988 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11989 | * their mobile plan. |
| 11990 | */ |
| 11991 | @Override |
| 11992 | public String getMobileProvisioningUrl() { |
| 11993 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11994 | final long identity = Binder.clearCallingIdentity(); |
| 11995 | try { |
| 11996 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11997 | } finally { |
| 11998 | Binder.restoreCallingIdentity(identity); |
| 11999 | } |
| 12000 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12001 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12002 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12003 | * Get the EAB contact from the EAB database. |
| 12004 | */ |
| 12005 | @Override |
| 12006 | public String getContactFromEab(String contact) { |
| 12007 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12008 | enforceModifyPermission(); |
| 12009 | final long identity = Binder.clearCallingIdentity(); |
| 12010 | try { |
| 12011 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12012 | } finally { |
| 12013 | Binder.restoreCallingIdentity(identity); |
| 12014 | } |
| 12015 | } |
| 12016 | |
| 12017 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12018 | * Get the EAB capability from the EAB database. |
| 12019 | */ |
| 12020 | @Override |
| 12021 | public String getCapabilityFromEab(String contact) { |
| 12022 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12023 | enforceModifyPermission(); |
| 12024 | final long identity = Binder.clearCallingIdentity(); |
| 12025 | try { |
| 12026 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12027 | } finally { |
| 12028 | Binder.restoreCallingIdentity(identity); |
| 12029 | } |
| 12030 | } |
| 12031 | |
| 12032 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12033 | * Remove the EAB contacts from the EAB database. |
| 12034 | */ |
| 12035 | @Override |
| 12036 | public int removeContactFromEab(int subId, String contacts) { |
| 12037 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12038 | enforceModifyPermission(); |
| 12039 | final long identity = Binder.clearCallingIdentity(); |
| 12040 | try { |
| 12041 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12042 | } finally { |
| 12043 | Binder.restoreCallingIdentity(identity); |
| 12044 | } |
| 12045 | } |
| 12046 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12047 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12048 | public boolean getDeviceUceEnabled() { |
| 12049 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12050 | final long identity = Binder.clearCallingIdentity(); |
| 12051 | try { |
| 12052 | return mApp.getDeviceUceEnabled(); |
| 12053 | } finally { |
| 12054 | Binder.restoreCallingIdentity(identity); |
| 12055 | } |
| 12056 | } |
| 12057 | |
| 12058 | @Override |
| 12059 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12060 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12061 | final long identity = Binder.clearCallingIdentity(); |
| 12062 | try { |
| 12063 | mApp.setDeviceUceEnabled(isEnabled); |
| 12064 | } finally { |
| 12065 | Binder.restoreCallingIdentity(identity); |
| 12066 | } |
| 12067 | } |
| 12068 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12069 | /** |
| 12070 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12071 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12072 | */ |
| 12073 | // Used for SHELL command only right now. |
| 12074 | @Override |
| 12075 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12076 | List<String> featureTags) { |
| 12077 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12078 | "addUceRegistrationOverrideShell"); |
| 12079 | final long identity = Binder.clearCallingIdentity(); |
| 12080 | try { |
| 12081 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12082 | new ArraySet<>(featureTags)); |
| 12083 | } catch (ImsException e) { |
| 12084 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12085 | } finally { |
| 12086 | Binder.restoreCallingIdentity(identity); |
| 12087 | } |
| 12088 | } |
| 12089 | |
| 12090 | /** |
| 12091 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12092 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12093 | */ |
| 12094 | // Used for SHELL command only right now. |
| 12095 | @Override |
| 12096 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12097 | List<String> featureTags) { |
| 12098 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12099 | "removeUceRegistrationOverrideShell"); |
| 12100 | final long identity = Binder.clearCallingIdentity(); |
| 12101 | try { |
| 12102 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12103 | new ArraySet<>(featureTags)); |
| 12104 | } catch (ImsException e) { |
| 12105 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12106 | } finally { |
| 12107 | Binder.restoreCallingIdentity(identity); |
| 12108 | } |
| 12109 | } |
| 12110 | |
| 12111 | /** |
| 12112 | * Clear all overrides in 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 clearUceRegistrationOverrideShell(int subId) { |
| 12118 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12119 | "clearUceRegistrationOverrideShell"); |
| 12120 | final long identity = Binder.clearCallingIdentity(); |
| 12121 | try { |
| 12122 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12123 | } catch (ImsException e) { |
| 12124 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12125 | } finally { |
| 12126 | Binder.restoreCallingIdentity(identity); |
| 12127 | } |
| 12128 | } |
| 12129 | |
| 12130 | /** |
| 12131 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12132 | */ |
| 12133 | // Used for SHELL command only right now. |
| 12134 | @Override |
| 12135 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12136 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12137 | "getLatestRcsContactUceCapabilityShell"); |
| 12138 | final long identity = Binder.clearCallingIdentity(); |
| 12139 | try { |
| 12140 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12141 | } catch (ImsException e) { |
| 12142 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12143 | } finally { |
| 12144 | Binder.restoreCallingIdentity(identity); |
| 12145 | } |
| 12146 | } |
| 12147 | |
| 12148 | /** |
| 12149 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12150 | * device does not have an active PUBLISH. |
| 12151 | */ |
| 12152 | // Used for SHELL command only right now. |
| 12153 | @Override |
| 12154 | public String getLastUcePidfXmlShell(int subId) { |
| 12155 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12156 | final long identity = Binder.clearCallingIdentity(); |
| 12157 | try { |
| 12158 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12159 | } catch (ImsException e) { |
| 12160 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12161 | } finally { |
| 12162 | Binder.restoreCallingIdentity(identity); |
| 12163 | } |
| 12164 | } |
| 12165 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12166 | /** |
| 12167 | * Remove UCE requests cannot be sent to the network status. |
| 12168 | */ |
| 12169 | // Used for SHELL command only right now. |
| 12170 | @Override |
| 12171 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12172 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12173 | final long identity = Binder.clearCallingIdentity(); |
| 12174 | try { |
| 12175 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12176 | } catch (ImsException e) { |
| 12177 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12178 | } finally { |
| 12179 | Binder.restoreCallingIdentity(identity); |
| 12180 | } |
| 12181 | } |
| 12182 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12183 | /** |
| 12184 | * Remove UCE requests cannot be sent to the network status. |
| 12185 | */ |
| 12186 | // Used for SHELL command only. |
| 12187 | @Override |
| 12188 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12189 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12190 | final long identity = Binder.clearCallingIdentity(); |
| 12191 | try { |
| 12192 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12193 | } catch (ImsException e) { |
| 12194 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12195 | } finally { |
| 12196 | Binder.restoreCallingIdentity(identity); |
| 12197 | } |
| 12198 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12199 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12200 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12201 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12202 | String callingPackage) { |
| 12203 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12204 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12205 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12206 | enforceTelephonyFeatureWithException(callingPackage, |
| 12207 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12208 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12209 | final int callingUid = Binder.getCallingUid(); |
| 12210 | // Verify that tha callingPackage belongs to the calling UID |
| 12211 | mApp.getSystemService(AppOpsManager.class) |
| 12212 | .checkPackage(callingUid, callingPackage); |
| 12213 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12214 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12215 | |
| 12216 | final long identity = Binder.clearCallingIdentity(); |
| 12217 | try { |
| 12218 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12219 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12220 | |
| 12221 | if (result instanceof IllegalStateException) { |
| 12222 | throw (IllegalStateException) result; |
| 12223 | } |
| 12224 | } finally { |
| 12225 | Binder.restoreCallingIdentity(identity); |
| 12226 | } |
| 12227 | } |
| 12228 | |
| 12229 | @Override |
| 12230 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12231 | String callingPackage) { |
| 12232 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12233 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12234 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12235 | enforceTelephonyFeatureWithException(callingPackage, |
| 12236 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12237 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12238 | final int callingUid = Binder.getCallingUid(); |
| 12239 | // Verify that tha callingPackage belongs to the calling UID |
| 12240 | mApp.getSystemService(AppOpsManager.class) |
| 12241 | .checkPackage(callingUid, callingPackage); |
| 12242 | |
| 12243 | final long identity = Binder.clearCallingIdentity(); |
| 12244 | try { |
| 12245 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12246 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12247 | |
| 12248 | if (result instanceof IllegalStateException) { |
| 12249 | throw (IllegalStateException) result; |
| 12250 | } |
| 12251 | } finally { |
| 12252 | Binder.restoreCallingIdentity(identity); |
| 12253 | } |
| 12254 | } |
| 12255 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12256 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12257 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12258 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12259 | // phone/system process do not have further restriction on request |
| 12260 | return; |
| 12261 | } |
| 12262 | |
| 12263 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12264 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12265 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12266 | context.enforceCallingOrSelfPermission( |
| 12267 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12268 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12269 | } |
| 12270 | |
| 12271 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12272 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12273 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12274 | || info.isEnabled()) { |
| 12275 | throw new IllegalArgumentException( |
| 12276 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12277 | } |
| 12278 | |
| 12279 | // Thresholds length for each RAN need in range. This has been validated in |
| 12280 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12281 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12282 | final int[] thresholds = info.getThresholds(); |
| 12283 | Objects.requireNonNull(thresholds); |
| 12284 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12285 | || thresholds.length |
| 12286 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12287 | throw new IllegalArgumentException( |
| 12288 | "thresholds length is out of range: " + thresholds.length); |
| 12289 | } |
| 12290 | } |
| 12291 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12292 | |
| 12293 | /** |
| 12294 | * Gets the current phone capability. |
| 12295 | * |
| 12296 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12297 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12298 | * It's used to evaluate possible phone config change, for example from single |
| 12299 | * SIM device to multi-SIM device. |
| 12300 | */ |
| 12301 | @Override |
| 12302 | public PhoneCapability getPhoneCapability() { |
| 12303 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12304 | |
| 12305 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12306 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12307 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12308 | final long identity = Binder.clearCallingIdentity(); |
| 12309 | try { |
| 12310 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12311 | } finally { |
| 12312 | Binder.restoreCallingIdentity(identity); |
| 12313 | } |
| 12314 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12315 | |
| 12316 | /** |
| 12317 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12318 | * required to be done shortly after the API is invoked. |
| 12319 | */ |
| 12320 | @Override |
| 12321 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12322 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12323 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12324 | enforceRebootPermission(); |
| 12325 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12326 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12327 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12328 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12329 | final long identity = Binder.clearCallingIdentity(); |
| 12330 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12331 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12332 | } finally { |
| 12333 | Binder.restoreCallingIdentity(identity); |
| 12334 | } |
| 12335 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12336 | |
| 12337 | /** |
| 12338 | * Request to get the current slicing configuration including URSP rules and |
| 12339 | * NSSAIs (configured, allowed and rejected). |
| 12340 | * |
| 12341 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12342 | */ |
| 12343 | @Override |
| 12344 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12345 | TelephonyPermissions |
| 12346 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12347 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12348 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12349 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12350 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12351 | "getSlicingConfig"); |
| 12352 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12353 | final long identity = Binder.clearCallingIdentity(); |
| 12354 | try { |
| 12355 | Phone phone = getDefaultPhone(); |
| 12356 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12357 | } finally { |
| 12358 | Binder.restoreCallingIdentity(identity); |
| 12359 | } |
| 12360 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12361 | |
| 12362 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12363 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12364 | * |
| 12365 | * @param capability The premium capability to check. |
| 12366 | * @param subId The subId to check the premium capability for. |
| 12367 | * |
| 12368 | * @return Whether the given premium capability is available to purchase. |
| 12369 | */ |
| 12370 | @Override |
| 12371 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12372 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12373 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12374 | log("Premium capability " |
| 12375 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12376 | + " is not available for purchase due to missing permissions."); |
| 12377 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12378 | + "permission READ_BASIC_PHONE_STATE."); |
| 12379 | } |
| 12380 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12381 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12382 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12383 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12384 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12385 | if (phone == null) { |
| 12386 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12387 | return false; |
| 12388 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12389 | final long identity = Binder.clearCallingIdentity(); |
| 12390 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12391 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12392 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12393 | } finally { |
| 12394 | Binder.restoreCallingIdentity(identity); |
| 12395 | } |
| 12396 | } |
| 12397 | |
| 12398 | /** |
| 12399 | * Purchase the given premium capability from the carrier. |
| 12400 | * |
| 12401 | * @param capability The premium capability to purchase. |
| 12402 | * @param callback The result of the purchase request. |
| 12403 | * @param subId The subId to purchase the premium capability for. |
| 12404 | */ |
| 12405 | @Override |
| 12406 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12407 | log("purchasePremiumCapability: capability=" |
| 12408 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12409 | + getCurrentPackageName()); |
| 12410 | |
| 12411 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12412 | mApp, "purchasePremiumCapability")) { |
| 12413 | log("purchasePremiumCapability " |
| 12414 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12415 | + " failed due to missing permissions."); |
| 12416 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12417 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12418 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12419 | mApp, "purchasePremiumCapability")) { |
| 12420 | log("purchasePremiumCapability " |
| 12421 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12422 | + " failed due to missing permissions."); |
| 12423 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12424 | } |
| 12425 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12426 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12427 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12428 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12429 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12430 | if (phone == null) { |
| 12431 | try { |
| 12432 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12433 | callback.accept(result); |
| 12434 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12435 | } catch (RemoteException e) { |
| 12436 | String logStr = "Purchase premium capability " |
| 12437 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12438 | + " failed due to RemoteException handling null phone: " + e; |
| 12439 | if (DBG) log(logStr); |
| 12440 | AnomalyReporter.reportAnomaly( |
| 12441 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12442 | } |
| 12443 | return; |
| 12444 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12445 | |
| 12446 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12447 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12448 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12449 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12450 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12451 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12452 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12453 | |
| 12454 | boolean isVisible = false; |
| 12455 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12456 | if (am != null) { |
| 12457 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12458 | if (processes != null) { |
| 12459 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12460 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12461 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12462 | if (process.processName.equals(callingProcess) && process.importance |
| 12463 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12464 | isVisible = true; |
| 12465 | break; |
| 12466 | } |
| 12467 | } |
| 12468 | } |
| 12469 | } |
| 12470 | |
| 12471 | if (!isVisible) { |
| 12472 | try { |
| 12473 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12474 | callback.accept(result); |
| 12475 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12476 | } catch (RemoteException e) { |
| 12477 | String logStr = "Purchase premium capability " |
| 12478 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12479 | + " failed due to RemoteException handling background application: " + e; |
| 12480 | if (DBG) log(logStr); |
| 12481 | AnomalyReporter.reportAnomaly( |
| 12482 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12483 | } |
| 12484 | return; |
| 12485 | } |
| 12486 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12487 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12488 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12489 | } |
| 12490 | |
| 12491 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12492 | * Register an IMS connection state callback |
| 12493 | */ |
| 12494 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12495 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12496 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12497 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12498 | // ImsMmTelManager |
| 12499 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12500 | TelephonyPermissions |
| 12501 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12502 | mApp, subId, "registerImsStateCallback"); |
| 12503 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12504 | // ImsRcsManager or SipDelegateManager |
| 12505 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12506 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12507 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12508 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12509 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12510 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12511 | } |
| 12512 | |
| 12513 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12514 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12515 | "IMS not available on device."); |
| 12516 | } |
| 12517 | |
| 12518 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12519 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12520 | } |
| 12521 | |
| 12522 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12523 | if (controller == null) { |
| 12524 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12525 | "IMS not available on device."); |
| 12526 | } |
| 12527 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12528 | if (callingPackage == null) { |
| 12529 | callingPackage = getCurrentPackageName(); |
| 12530 | } |
| 12531 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12532 | final long token = Binder.clearCallingIdentity(); |
| 12533 | try { |
| 12534 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12535 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12536 | } catch (ImsException e) { |
| 12537 | throw new ServiceSpecificException(e.getCode()); |
| 12538 | } finally { |
| 12539 | Binder.restoreCallingIdentity(token); |
| 12540 | } |
| 12541 | } |
| 12542 | |
| 12543 | /** |
| 12544 | * Unregister an IMS connection state callback |
| 12545 | */ |
| 12546 | @Override |
| 12547 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12548 | final long token = Binder.clearCallingIdentity(); |
| 12549 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12550 | if (controller == null) { |
| 12551 | return; |
| 12552 | } |
| 12553 | try { |
| 12554 | controller.unregisterImsStateCallback(cb); |
| 12555 | } finally { |
| 12556 | Binder.restoreCallingIdentity(token); |
| 12557 | } |
| 12558 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12559 | |
| 12560 | /** |
| 12561 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12562 | * |
| 12563 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12564 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12565 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12566 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12567 | * If there is current registered network this value will be same as the registered cell |
| 12568 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12569 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12570 | * it will be cleared and null will be returned. |
| 12571 | * |
| 12572 | */ |
| 12573 | @Override |
| 12574 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12575 | String callingFeatureId) { |
| 12576 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12577 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12578 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12579 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12580 | .setCallingPackage(callingPackage) |
| 12581 | .setCallingFeatureId(callingFeatureId) |
| 12582 | .setCallingPid(Binder.getCallingPid()) |
| 12583 | .setCallingUid(Binder.getCallingUid()) |
| 12584 | .setMethod("getLastKnownCellIdentity") |
| 12585 | .setLogAsInfo(true) |
| 12586 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12587 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12588 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12589 | .build()); |
| 12590 | |
| 12591 | boolean hasFinePermission = |
| 12592 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12593 | if (!hasFinePermission |
| 12594 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12595 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12596 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12597 | } |
| 12598 | |
| 12599 | final long identity = Binder.clearCallingIdentity(); |
| 12600 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12601 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12602 | if (sst == null) return null; |
| 12603 | return sst.getLastKnownCellIdentity(); |
| 12604 | } finally { |
| 12605 | Binder.restoreCallingIdentity(identity); |
| 12606 | } |
| 12607 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12608 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12609 | /** |
| 12610 | * Sets the modem service class Name that Telephony will bind to. |
| 12611 | * |
| 12612 | * @param serviceName The class name of the modem service. |
| 12613 | * @return true if the operation is succeed, otherwise false. |
| 12614 | */ |
| 12615 | public boolean setModemService(String serviceName) { |
| 12616 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12617 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12619 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12620 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12621 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12622 | } |
| 12623 | |
| 12624 | /** |
| 12625 | * Return the class name of the currently bounded modem service. |
| 12626 | * |
| 12627 | * @return the class name of the modem service. |
| 12628 | */ |
| 12629 | public String getModemService() { |
| 12630 | String result; |
| 12631 | Log.d(LOG_TAG, "getModemService"); |
| 12632 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12633 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12634 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12635 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12636 | "getModemService"); |
| 12637 | result = mPhoneConfigurationManager.getModemService(); |
| 12638 | Log.d(LOG_TAG, "result = " + result); |
| 12639 | return result; |
| 12640 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12641 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12642 | /** |
| 12643 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12644 | * including carrier config, entitlement server, and config update. |
| 12645 | * |
| 12646 | * @param subId subId The subscription ID of the carrier. |
| 12647 | * |
| 12648 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12649 | * be returned. |
| 12650 | * |
| 12651 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12652 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12653 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12654 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12655 | final long identity = Binder.clearCallingIdentity(); |
| 12656 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12657 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12658 | } finally { |
| 12659 | Binder.restoreCallingIdentity(identity); |
| 12660 | } |
| 12661 | } |
| 12662 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12663 | @Override |
| 12664 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12665 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12666 | mApp.enforceCallingOrSelfPermission( |
| 12667 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12668 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12669 | |
| 12670 | final long identity = Binder.clearCallingIdentity(); |
| 12671 | try { |
| 12672 | Phone phone = getPhone(subId); |
| 12673 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12674 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12675 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12676 | phone.setVoiceServiceStateOverride(hasService); |
| 12677 | } finally { |
| 12678 | Binder.restoreCallingIdentity(identity); |
| 12679 | } |
| 12680 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12681 | |
| 12682 | /** |
| 12683 | * set removable eSIM as default eUICC. |
| 12684 | * |
| 12685 | * @hide |
| 12686 | */ |
| 12687 | @Override |
| 12688 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12689 | enforceModifyPermission(); |
| 12690 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12691 | |
| 12692 | final long identity = Binder.clearCallingIdentity(); |
| 12693 | try { |
| 12694 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12695 | } finally { |
| 12696 | Binder.restoreCallingIdentity(identity); |
| 12697 | } |
| 12698 | } |
| 12699 | |
| 12700 | /** |
| 12701 | * Returns whether the removable eSIM is default eUICC or not. |
| 12702 | * |
| 12703 | * @hide |
| 12704 | */ |
| 12705 | @Override |
| 12706 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12707 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12708 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12709 | |
| 12710 | final long identity = Binder.clearCallingIdentity(); |
| 12711 | try { |
| 12712 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12713 | } finally { |
| 12714 | Binder.restoreCallingIdentity(identity); |
| 12715 | } |
| 12716 | } |
| 12717 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12718 | /** |
| 12719 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12720 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12721 | * application currently configured for this user. |
| 12722 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12723 | * {@code null} if the functionality is not supported. |
| 12724 | * @hide |
| 12725 | */ |
| 12726 | @Override |
| 12727 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12728 | boolean updateIfNeeded) { |
| 12729 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12730 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12731 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12732 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12733 | "getDefaultRespondViaMessageApplication"); |
| 12734 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12735 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12736 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12737 | UserHandle userHandle = null; |
| 12738 | final long identity = Binder.clearCallingIdentity(); |
| 12739 | try { |
| 12740 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12741 | } finally { |
| 12742 | Binder.restoreCallingIdentity(identity); |
| 12743 | } |
| 12744 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12745 | updateIfNeeded, userHandle); |
| 12746 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12747 | |
| 12748 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12749 | * Set whether the device is able to connect with null ciphering or integrity |
| 12750 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12751 | * and all new subscriptions after this. |
| 12752 | * |
| 12753 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12754 | * @hide |
| 12755 | */ |
| 12756 | @Override |
| 12757 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12758 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12759 | enforceModifyPermission(); |
| 12760 | checkForNullCipherAndIntegritySupport(); |
| 12761 | |
| 12762 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12763 | // for listening to these preference changes and applying them immediately. |
| 12764 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12765 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12766 | editor.apply(); |
| 12767 | |
| 12768 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12769 | phone.handleNullCipherEnabledChange(); |
| 12770 | } |
| 12771 | } |
| 12772 | |
| 12773 | |
| 12774 | /** |
| 12775 | * Get whether the device is able to connect with null ciphering or integrity |
| 12776 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12777 | * the state of the radio. |
| 12778 | * |
| 12779 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12780 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12781 | * version for this feature. |
| 12782 | * @hide |
| 12783 | */ |
| 12784 | @Override |
| 12785 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12786 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12787 | enforceReadPermission(); |
| 12788 | checkForNullCipherAndIntegritySupport(); |
| 12789 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12790 | } |
| 12791 | |
| 12792 | private void checkForNullCipherAndIntegritySupport() { |
| 12793 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12794 | throw new UnsupportedOperationException( |
| 12795 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12796 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12797 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12798 | throw new UnsupportedOperationException( |
| 12799 | "Null cipher and integrity operations unsupported by modem"); |
| 12800 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12801 | } |
| 12802 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12803 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12804 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12805 | throw new UnsupportedOperationException( |
| 12806 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12807 | + "above"); |
| 12808 | } |
| 12809 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12810 | throw new UnsupportedOperationException( |
| 12811 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12812 | } |
| 12813 | } |
| 12814 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12815 | private void checkForNullCipherNotificationSupport() { |
| 12816 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12817 | throw new UnsupportedOperationException( |
| 12818 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12819 | } |
| 12820 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12821 | throw new UnsupportedOperationException( |
| 12822 | "Null cipher notification operations unsupported by modem"); |
| 12823 | } |
| 12824 | } |
| 12825 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12826 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12827 | * Get the SIM state for the slot index. |
| 12828 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12829 | * |
| 12830 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12831 | */ |
| 12832 | @Override |
| 12833 | @SimState |
| 12834 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12835 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12836 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12837 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12838 | IccCardConstants.State simState; |
| 12839 | if (slotIndex < 0) { |
| 12840 | simState = IccCardConstants.State.UNKNOWN; |
| 12841 | } else { |
| 12842 | Phone phone = null; |
| 12843 | try { |
| 12844 | phone = PhoneFactory.getPhone(slotIndex); |
| 12845 | } catch (IllegalStateException e) { |
| 12846 | // ignore |
| 12847 | } |
| 12848 | if (phone == null) { |
| 12849 | simState = IccCardConstants.State.UNKNOWN; |
| 12850 | } else { |
| 12851 | IccCard icc = phone.getIccCard(); |
| 12852 | if (icc == null) { |
| 12853 | simState = IccCardConstants.State.UNKNOWN; |
| 12854 | } else { |
| 12855 | simState = icc.getState(); |
| 12856 | } |
| 12857 | } |
| 12858 | } |
| 12859 | return simState.ordinal(); |
| 12860 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12861 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12862 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12863 | boolean enableLogcat, |
| 12864 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12865 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12866 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12867 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12868 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12869 | ecdDataBuilder |
| 12870 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12871 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12872 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12873 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12874 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12875 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12876 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12877 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12878 | Executors.newCachedThreadPool(), db, |
| 12879 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12880 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12881 | } |
| 12882 | |
| 12883 | /** |
| 12884 | * Request telephony to persist state for debugging emergency call failures. |
| 12885 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12886 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12887 | * @param enableLogcat whether to collect logcat output |
| 12888 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12889 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12890 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12891 | */ |
| 12892 | @Override |
| 12893 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12894 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12895 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12896 | boolean enableTelephonyDump) { |
| 12897 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12898 | "persistEmergencyCallDiagnosticData"); |
| 12899 | final long identity = Binder.clearCallingIdentity(); |
| 12900 | try { |
| 12901 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12902 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12903 | |
| 12904 | } finally { |
| 12905 | Binder.restoreCallingIdentity(identity); |
| 12906 | } |
| 12907 | } |
| 12908 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12909 | /** |
| 12910 | * Get current cell broadcast ranges. |
| 12911 | */ |
| 12912 | @Override |
| 12913 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12914 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12915 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12916 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12917 | |
| 12918 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12919 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12920 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12921 | final long identity = Binder.clearCallingIdentity(); |
| 12922 | try { |
| 12923 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12924 | } finally { |
| 12925 | Binder.restoreCallingIdentity(identity); |
| 12926 | } |
| 12927 | } |
| 12928 | |
| 12929 | /** |
| 12930 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12931 | * |
| 12932 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12933 | */ |
| 12934 | @Override |
| 12935 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12936 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12937 | @Nullable IIntegerConsumer callback) { |
| 12938 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12939 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12940 | |
| 12941 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12942 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12943 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12944 | final long identity = Binder.clearCallingIdentity(); |
| 12945 | try { |
| 12946 | Phone phone = getPhoneFromSubId(subId); |
| 12947 | if (DBG) { |
| 12948 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12949 | } |
| 12950 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12951 | if (callback != null) { |
| 12952 | try { |
| 12953 | callback.accept(result); |
| 12954 | } catch (RemoteException e) { |
| 12955 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12956 | } |
| 12957 | } |
| 12958 | }); |
| 12959 | } finally { |
| 12960 | Binder.restoreCallingIdentity(identity); |
| 12961 | } |
| 12962 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12963 | |
| 12964 | /** |
| 12965 | * Returns whether the device supports the domain selection service. |
| 12966 | * |
| 12967 | * @return {@code true} if the device supports the domain selection service. |
| 12968 | */ |
| 12969 | @Override |
| 12970 | public boolean isDomainSelectionSupported() { |
| 12971 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12972 | "isDomainSelectionSupported"); |
| 12973 | |
| 12974 | final long identity = Binder.clearCallingIdentity(); |
| 12975 | try { |
| 12976 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12977 | } finally { |
| 12978 | Binder.restoreCallingIdentity(identity); |
| 12979 | } |
| 12980 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12981 | |
| 12982 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12983 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12984 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12985 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12986 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12987 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12988 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12989 | * {@code false} to disable. |
| 12990 | * @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] | 12991 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12992 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12993 | * |
| 12994 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12995 | */ |
| 12996 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12997 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 12998 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12999 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13000 | if (enableSatellite) { |
| 13001 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13002 | @Override |
| 13003 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13004 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13005 | + ", resultData=" + resultData); |
| 13006 | boolean isAllowed = false; |
| 13007 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13008 | callback::accept); |
| 13009 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13010 | if (resultData != null |
| 13011 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13012 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13013 | } else { |
| 13014 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13015 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13016 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13017 | result.accept(resultCode); |
| 13018 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13019 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13020 | if (isAllowed) { |
| 13021 | mSatelliteController.requestSatelliteEnabled( |
| 13022 | subId, enableSatellite, enableDemoMode, callback); |
| 13023 | } else { |
| 13024 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13025 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13026 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13027 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13028 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13029 | subId, resultReceiver); |
| 13030 | } else { |
| 13031 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13032 | mSatelliteController.requestSatelliteEnabled( |
| 13033 | subId, enableSatellite, enableDemoMode, callback); |
| 13034 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13035 | } |
| 13036 | |
| 13037 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13038 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13039 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13040 | * @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] | 13041 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13042 | * 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] | 13043 | * |
| 13044 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13045 | */ |
| 13046 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13047 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13048 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13049 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13050 | } |
| 13051 | |
| 13052 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13053 | * Request to get whether the satellite service demo mode is enabled. |
| 13054 | * |
| 13055 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13056 | * is enabled for. |
| 13057 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13058 | * if the request is successful or an error code if the request failed. |
| 13059 | * |
| 13060 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13061 | */ |
| 13062 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13063 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13064 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13065 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13066 | } |
| 13067 | |
| 13068 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13069 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13070 | * |
| 13071 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13072 | * is enabled for. |
| 13073 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13074 | * enabled if the request is successful or an error code if the request failed. |
| 13075 | * |
| 13076 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13077 | */ |
| 13078 | @Override |
| 13079 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13080 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
| 13081 | result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null); |
| 13082 | } |
| 13083 | |
| 13084 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13085 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13086 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13087 | * @param subId The subId of the subscription to check satellite service support for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13088 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13089 | * 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] | 13090 | */ |
| 13091 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13092 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13093 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13094 | } |
| 13095 | |
| 13096 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13097 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13098 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13099 | * @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] | 13100 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13101 | * 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] | 13102 | * |
| 13103 | * @throws SecurityException if the caller doesn't have required permission. |
| 13104 | */ |
| 13105 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13106 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13107 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13108 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13109 | } |
| 13110 | |
| 13111 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13112 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13113 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13114 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13115 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13116 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13117 | * @param resultCallback The callback to get the result of the request. |
| 13118 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13119 | * |
| 13120 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13121 | */ |
| 13122 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13123 | public void startSatelliteTransmissionUpdates(int subId, |
| 13124 | @NonNull IIntegerConsumer resultCallback, |
| 13125 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13126 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13127 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13128 | } |
| 13129 | |
| 13130 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13131 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13132 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13133 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13134 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13135 | * @param resultCallback The callback to get the result of the request. |
| 13136 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13137 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13138 | * |
| 13139 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13140 | */ |
| 13141 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13142 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13143 | @NonNull IIntegerConsumer resultCallback, |
| 13144 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13145 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13146 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13147 | } |
| 13148 | |
| 13149 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13150 | * Register the subscription with a satellite provider. |
| 13151 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13152 | * |
| 13153 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13154 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13155 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13156 | * @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] | 13157 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13158 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13159 | * @return The signal transport used by the caller to cancel the provision request, |
| 13160 | * or {@code null} if the request failed. |
| 13161 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13162 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13163 | */ |
| 13164 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13165 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13166 | @NonNull String token, @NonNull byte[] provisionData, |
| 13167 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13168 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13169 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13170 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13171 | } |
| 13172 | |
| 13173 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13174 | * Unregister the device/subscription with the satellite provider. |
| 13175 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13176 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13177 | * should report as deprovisioned. |
| 13178 | * |
| 13179 | * @param subId The subId of the subscription to be deprovisioned. |
| 13180 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13181 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13182 | * |
| 13183 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13184 | */ |
| 13185 | @Override |
| 13186 | public void deprovisionSatelliteService(int subId, |
| 13187 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13188 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13189 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13190 | } |
| 13191 | |
| 13192 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13193 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13194 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13195 | * @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] | 13196 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13197 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13198 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13199 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13200 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13201 | */ |
| 13202 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13203 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13204 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13205 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13206 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13207 | } |
| 13208 | |
| 13209 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13210 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13211 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13212 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13213 | * @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] | 13214 | * @param callback The callback that was passed to |
| 13215 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13216 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13217 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13218 | */ |
| 13219 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13220 | public void unregisterForSatelliteProvisionStateChanged( |
| 13221 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13222 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13223 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13224 | } |
| 13225 | |
| 13226 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13227 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13228 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13229 | * @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] | 13230 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13231 | * satellite provider if the request is successful or an error code if the |
| 13232 | * request failed. |
| 13233 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13234 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13235 | */ |
| 13236 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13237 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13238 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13239 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13240 | } |
| 13241 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13242 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13243 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13244 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13245 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13246 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13247 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13248 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13249 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13250 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13251 | */ |
| 13252 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13253 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13254 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13255 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13256 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13257 | } |
| 13258 | |
| 13259 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13260 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13261 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13262 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13263 | * @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] | 13264 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13265 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13266 | * |
| 13267 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13268 | */ |
| 13269 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13270 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13271 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13272 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13273 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13274 | } |
| 13275 | |
| 13276 | /** |
| 13277 | * Register to receive incoming datagrams over satellite. |
| 13278 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13279 | * @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] | 13280 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13281 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13282 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13283 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13284 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13285 | */ |
| 13286 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13287 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13288 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13289 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13290 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13291 | } |
| 13292 | |
| 13293 | /** |
| 13294 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13295 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13296 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13297 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13298 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13299 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13300 | * |
| 13301 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13302 | */ |
| 13303 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13304 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13305 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13306 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13307 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13308 | } |
| 13309 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13310 | /** |
| 13311 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13312 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13313 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13314 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13315 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13316 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13317 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13318 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13319 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13320 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13321 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13322 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13323 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13324 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13325 | } |
| 13326 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13327 | /** |
| 13328 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13329 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13330 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13331 | * input to this method. Datagram received here will be passed down to modem without any |
| 13332 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13333 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13334 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13335 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13336 | * SOS_SMS or LOCATION_SHARING. |
| 13337 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13338 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13339 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13340 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13341 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13342 | * |
| 13343 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13344 | */ |
| 13345 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13346 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13347 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13348 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13349 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13350 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13351 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13352 | } |
| 13353 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13354 | /** |
| 13355 | * Request to get whether satellite communication is allowed for the current location. |
| 13356 | * |
| 13357 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13358 | * allowed for the current location for. |
| 13359 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13360 | * for the current location if the request is successful or an error code |
| 13361 | * if the request failed. |
| 13362 | * |
| 13363 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13364 | */ |
| 13365 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13366 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13367 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13368 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13369 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13370 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13371 | } |
| 13372 | |
| 13373 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13374 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13375 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13376 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13377 | * @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] | 13378 | * be visible if the request is successful or an error code if the request failed. |
| 13379 | * |
| 13380 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13381 | */ |
| 13382 | @Override |
| 13383 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13384 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13385 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13386 | } |
| 13387 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13388 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13389 | * Inform that Device is aligned to satellite for demo mode. |
| 13390 | * |
| 13391 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13392 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13393 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13394 | * |
| 13395 | * @throws SecurityException if the caller doesn't have required permission. |
| 13396 | */ |
| 13397 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13398 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13399 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13400 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13401 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13402 | } |
| 13403 | |
| 13404 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13405 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13406 | * by modem. |
| 13407 | * |
| 13408 | * @param subId The subId of the subscription to request for. |
| 13409 | * @param reason Reason for disallowing satellite communication for carrier. |
| 13410 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 13411 | * operation. |
| 13412 | * |
| 13413 | * @throws SecurityException if the caller doesn't have required permission. |
| 13414 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13415 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13416 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13417 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13418 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13419 | final long identity = Binder.clearCallingIdentity(); |
| 13420 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13421 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13422 | } finally { |
| 13423 | Binder.restoreCallingIdentity(identity); |
| 13424 | } |
| 13425 | } |
| 13426 | |
| 13427 | /** |
| 13428 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13429 | * by modem. |
| 13430 | * |
| 13431 | * @param subId The subId of the subscription to request for. |
| 13432 | * @param reason Reason for disallowing satellite communication. |
| 13433 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 13434 | * operation. |
| 13435 | * |
| 13436 | * @throws SecurityException if the caller doesn't have required permission. |
| 13437 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13438 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13439 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13440 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13441 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13442 | final long identity = Binder.clearCallingIdentity(); |
| 13443 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13444 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13445 | } finally { |
| 13446 | Binder.restoreCallingIdentity(identity); |
| 13447 | } |
| 13448 | } |
| 13449 | |
| 13450 | /** |
| 13451 | * Get reasons for disallowing satellite communication, as requested by |
| 13452 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 13453 | * |
| 13454 | * @param subId The subId of the subscription to request for. |
| 13455 | * |
| 13456 | * @return Integer array of reasons for disallowing satellite communication. |
| 13457 | * |
| 13458 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13459 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13460 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13461 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13462 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13463 | final long identity = Binder.clearCallingIdentity(); |
| 13464 | try { |
| 13465 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13466 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13467 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13468 | } finally { |
| 13469 | Binder.restoreCallingIdentity(identity); |
| 13470 | } |
| 13471 | } |
| 13472 | |
| 13473 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13474 | * Request to get the signal strength of the satellite connection. |
| 13475 | * |
| 13476 | * @param subId The subId of the subscription to request for. |
| 13477 | * @param result Result receiver to get the error code of the request and the current signal |
| 13478 | * strength of the satellite connection. |
| 13479 | * |
| 13480 | * @throws SecurityException if the caller doesn't have required permission. |
| 13481 | */ |
| 13482 | @Override |
| 13483 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13484 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13485 | final long identity = Binder.clearCallingIdentity(); |
| 13486 | try { |
| 13487 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13488 | } finally { |
| 13489 | Binder.restoreCallingIdentity(identity); |
| 13490 | } |
| 13491 | } |
| 13492 | |
| 13493 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13494 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13495 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13496 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13497 | * |
| 13498 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13499 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13500 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13501 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13502 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13503 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13504 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13505 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13506 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13507 | */ |
| 13508 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13509 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13510 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13511 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13512 | final long identity = Binder.clearCallingIdentity(); |
| 13513 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13514 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13515 | } finally { |
| 13516 | Binder.restoreCallingIdentity(identity); |
| 13517 | } |
| 13518 | } |
| 13519 | |
| 13520 | /** |
| 13521 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13522 | * If callback was not registered before, the request will be ignored. |
| 13523 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13524 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13525 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13526 | * @param callback The callback that was passed to |
| 13527 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13528 | * |
| 13529 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13530 | */ |
| 13531 | @Override |
| 13532 | public void unregisterForNtnSignalStrengthChanged( |
| 13533 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13534 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13535 | final long identity = Binder.clearCallingIdentity(); |
| 13536 | try { |
| 13537 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13538 | } finally { |
| 13539 | Binder.restoreCallingIdentity(identity); |
| 13540 | } |
| 13541 | } |
| 13542 | |
| 13543 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13544 | * Registers for satellite capabilities change event from the satellite service. |
| 13545 | * |
| 13546 | * @param subId The subId of the subscription to request for. |
| 13547 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13548 | * |
| 13549 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13550 | * |
| 13551 | * @throws SecurityException if the caller doesn't have required permission. |
| 13552 | */ |
| 13553 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13554 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13555 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13556 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13557 | final long identity = Binder.clearCallingIdentity(); |
| 13558 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13559 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13560 | } finally { |
| 13561 | Binder.restoreCallingIdentity(identity); |
| 13562 | } |
| 13563 | } |
| 13564 | |
| 13565 | /** |
| 13566 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13567 | * If callback was not registered before, the request will be ignored. |
| 13568 | * |
| 13569 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13570 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13571 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13572 | * |
| 13573 | * @throws SecurityException if the caller doesn't have required permission. |
| 13574 | */ |
| 13575 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13576 | public void unregisterForCapabilitiesChanged(int subId, |
| 13577 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13578 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13579 | final long identity = Binder.clearCallingIdentity(); |
| 13580 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13581 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13582 | } finally { |
| 13583 | Binder.restoreCallingIdentity(identity); |
| 13584 | } |
| 13585 | } |
| 13586 | |
| 13587 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13588 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13589 | * |
| 13590 | * @param servicePackageName The package name of the satellite vendor service. |
| 13591 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13592 | * {@code false} otherwise. |
| 13593 | */ |
| 13594 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13595 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13596 | TelephonyPermissions.enforceShellOnly( |
| 13597 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13598 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13599 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13600 | "setSatelliteServicePackageName"); |
| 13601 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13602 | } |
| 13603 | |
| 13604 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13605 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13606 | * |
| 13607 | * @param servicePackageName The package name of the satellite gateway service. |
| 13608 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13609 | * {@code false} otherwise. |
| 13610 | */ |
| 13611 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13612 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13613 | TelephonyPermissions.enforceShellOnly( |
| 13614 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13616 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13617 | "setSatelliteGatewayServicePackageName"); |
| 13618 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13619 | } |
| 13620 | |
| 13621 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13622 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13623 | * |
| 13624 | * @param packageName The package name of the satellite pointing UI app. |
| 13625 | * @param className The class name of the satellite pointing UI app. |
| 13626 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13627 | * {@code false} otherwise. |
| 13628 | */ |
| 13629 | public boolean setSatellitePointingUiClassName( |
| 13630 | @Nullable String packageName, @Nullable String className) { |
| 13631 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13632 | + ", className=" + className); |
| 13633 | TelephonyPermissions.enforceShellOnly( |
| 13634 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13636 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13637 | "setSatelliteGatewayServicePackageName"); |
| 13638 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13639 | } |
| 13640 | |
| 13641 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13642 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13643 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13644 | * listening mode. |
| 13645 | * |
| 13646 | * @param timeoutMillis The timeout duration in millisecond. |
| 13647 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13648 | */ |
| 13649 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13650 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13651 | TelephonyPermissions.enforceShellOnly( |
| 13652 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13653 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13654 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13655 | "setSatelliteListeningTimeoutDuration"); |
| 13656 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13657 | } |
| 13658 | |
| 13659 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13660 | * This API can be used by only CTS to override the timeout durations used by the |
| 13661 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13662 | * |
| 13663 | * @param timeoutMillis The timeout duration in millisecond. |
| 13664 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13665 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13666 | public boolean setDatagramControllerTimeoutDuration( |
| 13667 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13668 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13669 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13670 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13671 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13673 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13674 | "setDatagramControllerTimeoutDuration"); |
| 13675 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13676 | reset, timeoutType, timeoutMillis); |
| 13677 | } |
| 13678 | |
| 13679 | /** |
| 13680 | * This API can be used by only CTS to override the timeout durations used by the |
| 13681 | * SatelliteController module. |
| 13682 | * |
| 13683 | * @param timeoutMillis The timeout duration in millisecond. |
| 13684 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13685 | */ |
| 13686 | public boolean setSatelliteControllerTimeoutDuration( |
| 13687 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13688 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13689 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13690 | TelephonyPermissions.enforceShellOnly( |
| 13691 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13692 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13693 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13694 | "setSatelliteControllerTimeoutDuration"); |
| 13695 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13696 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13697 | } |
| 13698 | |
| 13699 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13700 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13701 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13702 | * |
| 13703 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13704 | * of the following values to enable the override: |
| 13705 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13706 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13707 | * To disable the override, use -1 for handoverType. |
| 13708 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13709 | * delaySeconds after the emergency call starts. |
| 13710 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13711 | */ |
| 13712 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13713 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13714 | TelephonyPermissions.enforceShellOnly( |
| 13715 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13717 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13718 | "setEmergencyCallToSatelliteHandoverType"); |
| 13719 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13720 | handoverType, delaySeconds); |
| 13721 | } |
| 13722 | |
| 13723 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13724 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13725 | * |
| 13726 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13727 | * otherwise. |
| 13728 | * @param isProvisioned The overriding provision status. |
| 13729 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13730 | */ |
| 13731 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13732 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13733 | + ", isProvisioned=" + isProvisioned); |
| 13734 | TelephonyPermissions.enforceShellOnly( |
| 13735 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13737 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13738 | "setOemEnabledSatelliteProvisionStatus"); |
| 13739 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13740 | } |
| 13741 | |
| 13742 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13743 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13744 | * |
| 13745 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13746 | */ |
| 13747 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13748 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13749 | long locationCountryCodeTimestampNanos) { |
| 13750 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13751 | + String.join(", ", currentNetworkCountryCodes) |
| 13752 | + ", locationCountryCode=" + locationCountryCode |
| 13753 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13754 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13755 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13756 | TelephonyPermissions.enforceShellOnly( |
| 13757 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13758 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13759 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13760 | "setCachedLocationCountryCode"); |
| 13761 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13762 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13763 | locationCountryCodeTimestampNanos); |
| 13764 | } |
| 13765 | |
| 13766 | /** |
| 13767 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13768 | * access controller. |
| 13769 | * |
| 13770 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13771 | * otherwise. |
| 13772 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13773 | */ |
| 13774 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13775 | String s2CellFile, long locationFreshDurationNanos, |
| 13776 | List<String> satelliteCountryCodes) { |
| 13777 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13778 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13779 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13780 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13781 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13782 | TelephonyPermissions.enforceShellOnly( |
| 13783 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13785 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13786 | "setSatelliteAccessControlOverlayConfigs"); |
| 13787 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13788 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13789 | } |
| 13790 | |
| 13791 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13792 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13793 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13794 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13795 | * |
| 13796 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13797 | * satellite modem or not. |
| 13798 | * |
| 13799 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13800 | */ |
| 13801 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13802 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13803 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13804 | + "disabled"); |
| 13805 | return false; |
| 13806 | } |
| 13807 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13808 | TelephonyPermissions.enforceShellOnly( |
| 13809 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13810 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13811 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13812 | "setShouldSendDatagramToModemInDemoMode"); |
| 13813 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13814 | shouldSendToModemInDemoMode); |
| 13815 | } |
| 13816 | |
| 13817 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 13818 | * Sets the service defined in ComponentName to be bound. |
| 13819 | * |
| 13820 | * This should only be used for testing. |
| 13821 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 13822 | * {@code false} otherwise. |
| 13823 | */ |
| 13824 | @Override |
| 13825 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 13826 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 13827 | |
| 13828 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13829 | "setDomainSelectionServiceOverride"); |
| 13830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13831 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 13832 | |
| 13833 | final long identity = Binder.clearCallingIdentity(); |
| 13834 | try { |
| 13835 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13836 | return DomainSelectionResolver.getInstance() |
| 13837 | .setDomainSelectionServiceOverride(componentName); |
| 13838 | } |
| 13839 | } finally { |
| 13840 | Binder.restoreCallingIdentity(identity); |
| 13841 | } |
| 13842 | return false; |
| 13843 | } |
| 13844 | |
| 13845 | /** |
| 13846 | * Clears the DomainSelectionService override. |
| 13847 | * |
| 13848 | * This should only be used for testing. |
| 13849 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 13850 | * {@code false} otherwise. |
| 13851 | */ |
| 13852 | @Override |
| 13853 | public boolean clearDomainSelectionServiceOverride() { |
| 13854 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 13855 | |
| 13856 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13857 | "clearDomainSelectionServiceOverride"); |
| 13858 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13859 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 13860 | |
| 13861 | final long identity = Binder.clearCallingIdentity(); |
| 13862 | try { |
| 13863 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13864 | return DomainSelectionResolver.getInstance() |
| 13865 | .clearDomainSelectionServiceOverride(); |
| 13866 | } |
| 13867 | } finally { |
| 13868 | Binder.restoreCallingIdentity(identity); |
| 13869 | } |
| 13870 | return false; |
| 13871 | } |
| 13872 | |
| 13873 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13874 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 13875 | * |
| 13876 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 13877 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 13878 | * identifier is sent in the clear, which has privacy implications for the user. |
| 13879 | * |
| 13880 | * @param enable if notifications about disclosure events should be enabled |
| 13881 | * @throws SecurityException if the caller does not have the required privileges |
| 13882 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13883 | */ |
| 13884 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13885 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13886 | enforceModifyPermission(); |
| 13887 | checkForIdentifierDisclosureNotificationSupport(); |
| 13888 | |
| 13889 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13890 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 13891 | editor.apply(); |
| 13892 | |
| 13893 | // Each phone instance is responsible for updating its respective modem immediately |
| 13894 | // after we've made a preference change. |
| 13895 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13896 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 13897 | } |
| 13898 | } |
| 13899 | |
| 13900 | /** |
| 13901 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 13902 | * |
| 13903 | * @throws SecurityException if the caller does not have the required privileges |
| 13904 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13905 | */ |
| 13906 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13907 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13908 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 13909 | checkForIdentifierDisclosureNotificationSupport(); |
| 13910 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 13911 | } |
| 13912 | |
| 13913 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 13914 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 13915 | * are in use by the cellular modem. |
| 13916 | * |
| 13917 | * @throws IllegalStateException if the Telephony process is not currently available |
| 13918 | * @throws SecurityException if the caller does not have the required privileges |
| 13919 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 13920 | * and integrity algorithms in use |
| 13921 | * @hide |
| 13922 | */ |
| 13923 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 13924 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 13925 | enforceModifyPermission(); |
| 13926 | checkForNullCipherNotificationSupport(); |
| 13927 | |
| 13928 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13929 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 13930 | editor.apply(); |
| 13931 | |
| 13932 | // Each phone instance is responsible for updating its respective modem immediately |
| 13933 | // after a preference change. |
| 13934 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13935 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 13936 | } |
| 13937 | } |
| 13938 | |
| 13939 | /** |
| 13940 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 13941 | * cellular modem. |
| 13942 | * |
| 13943 | * @throws IllegalStateException if the Telephony process is not currently available |
| 13944 | * @throws SecurityException if the caller does not have the required privileges |
| 13945 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 13946 | * and integrity algorithms in use |
| 13947 | * @hide |
| 13948 | */ |
| 13949 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 13950 | public boolean isNullCipherNotificationsEnabled() { |
| 13951 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 13952 | checkForNullCipherNotificationSupport(); |
| 13953 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 13954 | } |
| 13955 | |
| 13956 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13957 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 13958 | * |
| 13959 | * <p>This method behaves in one of the following ways: |
| 13960 | * <ul> |
| 13961 | * <li>return true : if the calling package has the appop permission {@link |
| 13962 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 13963 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 13964 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 13965 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 13966 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 13967 | * </ul> |
| 13968 | */ |
| 13969 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 13970 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 13971 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13972 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 13973 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 13974 | return true; |
| 13975 | } |
| 13976 | } |
| 13977 | return false; |
| 13978 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13979 | |
| 13980 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13981 | * @return The subscription manager service instance. |
| 13982 | */ |
| 13983 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 13984 | return SubscriptionManagerService.getInstance(); |
| 13985 | } |
| 13986 | |
| 13987 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13988 | * Class binds the consumer[callback] and carrierId. |
| 13989 | */ |
| 13990 | private static class CallerCallbackInfo { |
| 13991 | private final Consumer<Integer> mConsumer; |
| 13992 | private final int mCarrierId; |
| 13993 | |
| 13994 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 13995 | mConsumer = consumer; |
| 13996 | mCarrierId = carrierId; |
| 13997 | } |
| 13998 | |
| 13999 | public Consumer<Integer> getConsumer() { |
| 14000 | return mConsumer; |
| 14001 | } |
| 14002 | |
| 14003 | public int getCarrierId() { |
| 14004 | return mCarrierId; |
| 14005 | } |
| 14006 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14007 | |
| 14008 | /* |
| 14009 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14010 | * But the context that is passed in is unused if the phone app is already alive. |
| 14011 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14012 | */ |
| 14013 | @VisibleForTesting |
| 14014 | public void setPackageManager(PackageManager packageManager) { |
| 14015 | mPackageManager = packageManager; |
| 14016 | } |
| 14017 | |
| 14018 | /* |
| 14019 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14020 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14021 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14022 | */ |
| 14023 | @VisibleForTesting |
| 14024 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14025 | mFeatureFlags = featureFlags; |
| 14026 | } |
| 14027 | |
| 14028 | /** |
| 14029 | * Make sure the device has required telephony feature |
| 14030 | * |
| 14031 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14032 | */ |
| 14033 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14034 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14035 | if (callingPackage == null || mPackageManager == null) { |
| 14036 | return; |
| 14037 | } |
| 14038 | |
| 14039 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14040 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
| 14041 | Binder.getCallingUserHandle())) { |
| 14042 | return; |
| 14043 | } |
| 14044 | |
| 14045 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14046 | throw new UnsupportedOperationException( |
| 14047 | methodName + " is unsupported without " + telephonyFeature); |
| 14048 | } |
| 14049 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14050 | } |