Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS; |
| 20 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 22 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 23 | import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 24 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 26 | import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; |
| 27 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED; |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 29 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 30 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 31 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 32 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 34 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 35 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 36 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 37 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 38 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 39 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 40 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 41 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 42 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 44 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 45 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 46 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 47 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 48 | import android.compat.annotation.ChangeId; |
| 49 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 50 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 51 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 52 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.content.Context; |
| 54 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 55 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 56 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 57 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.net.Uri; |
| 59 | import android.os.AsyncResult; |
| 60 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 61 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 62 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 63 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 65 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 66 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 67 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.os.Looper; |
| 69 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 71 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 72 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 74 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 75 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 76 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 77 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 78 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 80 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 81 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 82 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 83 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 84 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 85 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 86 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 87 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 88 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 89 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 90 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 91 | import android.telephony.AccessNetworkConstants; |
| 92 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 93 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 94 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 95 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 96 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 97 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 98 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 99 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 100 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 101 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 102 | import android.telephony.CellIdentityCdma; |
| 103 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 105 | import android.telephony.CellInfoGsm; |
| 106 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 107 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 108 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 110 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 111 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 112 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 113 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 114 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 115 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 116 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 117 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 118 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 119 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 121 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 122 | import android.telephony.SignalStrengthUpdateRequest; |
| 123 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 124 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 126 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 127 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 130 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 131 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 132 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 133 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 134 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 135 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 136 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 137 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 138 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 139 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 140 | import android.telephony.gba.GbaAuthRequest; |
| 141 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 142 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 143 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 145 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 146 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 147 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 154 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 155 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 156 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 158 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 160 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame^] | 162 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 164 | import android.telephony.satellite.NtnSignalStrength; |
| 165 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 166 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 167 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 172 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 173 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 176 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 177 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 178 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 179 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 180 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 195 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 212 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 213 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 215 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 217 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 218 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 219 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 221 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 222 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 226 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 228 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 231 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 232 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 233 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 234 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 235 | import com.android.internal.telephony.uicc.IccIoResult; |
| 236 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 238 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 239 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 243 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 244 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 245 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 246 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 247 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 248 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 249 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 250 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 251 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 252 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 253 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 254 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 255 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 256 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 257 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 258 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 259 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 260 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 261 | import com.android.services.telephony.TelecomAccountRegistry; |
| 262 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 263 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 264 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 265 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 266 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 267 | import java.io.IOException; |
| 268 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 269 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 270 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 271 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 272 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 273 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 274 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 275 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 276 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 277 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 278 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 279 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 280 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 281 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 282 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 283 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 284 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 285 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * Implementation of the ITelephony interface. |
| 289 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 290 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 292 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 293 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 294 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 295 | |
| 296 | // Message codes used with mMainThreadHandler |
| 297 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 298 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 299 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 300 | private static final int CMD_OPEN_CHANNEL = 9; |
| 301 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 302 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 303 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 304 | private static final int CMD_NV_READ_ITEM = 13; |
| 305 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 306 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 307 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 308 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 309 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 310 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 311 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 312 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 313 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 314 | private static final int CMD_SEND_ENVELOPE = 25; |
| 315 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 316 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 317 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 318 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 319 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 320 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 321 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 322 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 323 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 324 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 325 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 326 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 327 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 328 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 329 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 330 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 331 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 332 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 333 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 334 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 335 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 336 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 337 | private static final int CMD_SWITCH_SLOTS = 50; |
| 338 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 339 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 340 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 341 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 342 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 343 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 344 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 345 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 346 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 347 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 348 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 349 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 350 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 351 | private static final int CMD_MODEM_REBOOT = 64; |
| 352 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 353 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 354 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 355 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 356 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 357 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 358 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 359 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 360 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 361 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 362 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 363 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 364 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 365 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 366 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 367 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 368 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 369 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 370 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 371 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 372 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 373 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 374 | private static final int CMD_GET_CALL_WAITING = 87; |
| 375 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 376 | private static final int CMD_SET_CALL_WAITING = 89; |
| 377 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 378 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 379 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 380 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 381 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 382 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 383 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 384 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 385 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 386 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 387 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 388 | private static final int CMD_SET_SIM_POWER = 101; |
| 389 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 390 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 391 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 392 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 393 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 394 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 395 | 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] | 396 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 397 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 398 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 399 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 400 | private static final int CMD_ENABLE_VONR = 113; |
| 401 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 402 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 403 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 404 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 405 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 406 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 407 | // Parameters of select command. |
| 408 | private static final int SELECT_COMMAND = 0xA4; |
| 409 | private static final int SELECT_P1 = 0x04; |
| 410 | private static final int SELECT_P2 = 0; |
| 411 | private static final int SELECT_P3 = 0x10; |
| 412 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 413 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 414 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 415 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 416 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 417 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 418 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 419 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 420 | /** The singleton instance. */ |
| 421 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 422 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 424 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 425 | private FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 426 | private final CallManager mCM; |
| 427 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 428 | |
| 429 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 430 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 431 | private final UserManager mUserManager; |
| 432 | private final AppOpsManager mAppOps; |
| 433 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 434 | private final SharedPreferences mTelephonySharedPreferences; |
| 435 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 436 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 437 | private PackageManager mPackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 439 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 440 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 441 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 442 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 443 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 444 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 445 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 446 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 447 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 448 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 449 | // String to store multi SIM allowed |
| 450 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 451 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 452 | // The AID of ISD-R. |
| 453 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 454 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 455 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 456 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 457 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 458 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 459 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 460 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 461 | 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] | 462 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 463 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 464 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 465 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 466 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 467 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 468 | */ |
| 469 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 470 | "reset_network_erase_modem_config_enabled"; |
| 471 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 472 | 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] | 473 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 474 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 475 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 476 | /** |
| 477 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 478 | * one ICCID active at the same time. |
| 479 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 480 | * |
| 481 | * @hide |
| 482 | */ |
| 483 | @ChangeId |
| 484 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 485 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 486 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 487 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 488 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 489 | * operation fails. |
| 490 | */ |
| 491 | @ChangeId |
| 492 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 493 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 494 | |
| 495 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | * A request object to use for transmitting data to an ICC. |
| 497 | */ |
| 498 | private static final class IccAPDUArgument { |
| 499 | public int channel, cla, command, p1, p2, p3; |
| 500 | public String data; |
| 501 | |
| 502 | public IccAPDUArgument(int channel, int cla, int command, |
| 503 | int p1, int p2, int p3, String data) { |
| 504 | this.channel = channel; |
| 505 | this.cla = cla; |
| 506 | this.command = command; |
| 507 | this.p1 = p1; |
| 508 | this.p2 = p2; |
| 509 | this.p3 = p3; |
| 510 | this.data = data; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 515 | * A request object to use for transmitting data to an ICC. |
| 516 | */ |
| 517 | private static final class ManualNetworkSelectionArgument { |
| 518 | public OperatorInfo operatorInfo; |
| 519 | public boolean persistSelection; |
| 520 | |
| 521 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 522 | this.operatorInfo = operatorInfo; |
| 523 | this.persistSelection = persistSelection; |
| 524 | } |
| 525 | } |
| 526 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 527 | private static final class PurchasePremiumCapabilityArgument { |
| 528 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 529 | public @NonNull IIntegerConsumer callback; |
| 530 | |
| 531 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 532 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 533 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 534 | this.callback = callback; |
| 535 | } |
| 536 | } |
| 537 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 538 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 540 | * request after sending. The main thread will notify the request when it is complete. |
| 541 | */ |
| 542 | private static final class MainThreadRequest { |
| 543 | /** The argument to use for the request */ |
| 544 | public Object argument; |
| 545 | /** The result of the request that is run on the main thread */ |
| 546 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 547 | // The subscriber id that this request applies to. Defaults to |
| 548 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 549 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 550 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 551 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 552 | public Phone phone; |
| 553 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 554 | public WorkSource workSource; |
| 555 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 556 | public MainThreadRequest(Object argument) { |
| 557 | this.argument = argument; |
| 558 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 559 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 560 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 561 | this.argument = argument; |
| 562 | if (phone != null) { |
| 563 | this.phone = phone; |
| 564 | } |
| 565 | this.workSource = workSource; |
| 566 | } |
| 567 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 568 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 569 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 570 | if (subId != null) { |
| 571 | this.subId = subId; |
| 572 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 573 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 574 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 577 | private static final class IncomingThirdPartyCallArgs { |
| 578 | public final ComponentName component; |
| 579 | public final String callId; |
| 580 | public final String callerDisplayName; |
| 581 | |
| 582 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 583 | String callerDisplayName) { |
| 584 | this.component = component; |
| 585 | this.callId = callId; |
| 586 | this.callerDisplayName = callerDisplayName; |
| 587 | } |
| 588 | } |
| 589 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 590 | /** |
| 591 | * A handler that processes messages on the main thread in the phone process. Since many |
| 592 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 593 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 594 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 595 | * on, which will be notified when the operation completes and will contain the result of the |
| 596 | * request. |
| 597 | * |
| 598 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 599 | * note that request.result must be set to something non-null for the calling thread to |
| 600 | * unblock. |
| 601 | */ |
| 602 | private final class MainThreadHandler extends Handler { |
| 603 | @Override |
| 604 | public void handleMessage(Message msg) { |
| 605 | MainThreadRequest request; |
| 606 | Message onCompleted; |
| 607 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 608 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 610 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 611 | |
| 612 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 613 | case CMD_HANDLE_USSD_REQUEST: { |
| 614 | request = (MainThreadRequest) msg.obj; |
| 615 | final Phone phone = getPhoneFromRequest(request); |
| 616 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 617 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 619 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | if (!isUssdApiAllowed(request.subId)) { |
| 621 | // Carrier does not support use of this API, return failure. |
| 622 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 623 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 624 | Bundle returnData = new Bundle(); |
| 625 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 626 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 627 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | request.result = true; |
| 629 | notifyRequester(request); |
| 630 | return; |
| 631 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 632 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 633 | try { |
| 634 | request.result = phone != null |
| 635 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 636 | } catch (CallStateException cse) { |
| 637 | request.result = false; |
| 638 | } |
| 639 | // Wake up the requesting thread |
| 640 | notifyRequester(request); |
| 641 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 644 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 645 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 646 | final Phone phone = getPhoneFromRequest(request); |
| 647 | request.result = phone != null ? |
| 648 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 649 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 650 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 651 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 652 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 653 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 654 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 655 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 657 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 658 | uiccPort = getUiccPortFromRequest(request); |
| 659 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 660 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 661 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 665 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 666 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 667 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 668 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 669 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 670 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | break; |
| 672 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | ar = (AsyncResult) msg.obj; |
| 675 | request = (MainThreadRequest) ar.userObj; |
| 676 | if (ar.exception == null && ar.result != null) { |
| 677 | request.result = ar.result; |
| 678 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 679 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | if (ar.result == null) { |
| 681 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 685 | } else { |
| 686 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 687 | } |
| 688 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 689 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | break; |
| 691 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 692 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 693 | request = (MainThreadRequest) msg.obj; |
| 694 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 695 | uiccPort = getUiccPortFromRequest(request); |
| 696 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 697 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 698 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 699 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 700 | } else { |
| 701 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 702 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 703 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 704 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 705 | iccArgument.p2, |
| 706 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | } |
| 708 | break; |
| 709 | |
| 710 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 711 | ar = (AsyncResult) msg.obj; |
| 712 | request = (MainThreadRequest) ar.userObj; |
| 713 | if (ar.exception == null && ar.result != null) { |
| 714 | request.result = ar.result; |
| 715 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 716 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | if (ar.result == null) { |
| 718 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 719 | } else if (ar.exception instanceof CommandException) { |
| 720 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 721 | ar.exception); |
| 722 | } else { |
| 723 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 724 | } |
| 725 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 726 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case CMD_EXCHANGE_SIM_IO: |
| 730 | request = (MainThreadRequest) msg.obj; |
| 731 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 732 | uiccPort = getUiccPortFromRequest(request); |
| 733 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 734 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 735 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 736 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 737 | } else { |
| 738 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 739 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 740 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 742 | iccArgument.data, onCompleted); |
| 743 | } |
| 744 | break; |
| 745 | |
| 746 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 747 | ar = (AsyncResult) msg.obj; |
| 748 | request = (MainThreadRequest) ar.userObj; |
| 749 | if (ar.exception == null && ar.result != null) { |
| 750 | request.result = ar.result; |
| 751 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 752 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 753 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 754 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 755 | break; |
| 756 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 757 | case CMD_SEND_ENVELOPE: |
| 758 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 759 | uiccPort = getUiccPortFromRequest(request); |
| 760 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 761 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 762 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 763 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 764 | } else { |
| 765 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 766 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 767 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case EVENT_SEND_ENVELOPE_DONE: |
| 771 | ar = (AsyncResult) msg.obj; |
| 772 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 773 | if (ar.exception == null && ar.result != null) { |
| 774 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 775 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 776 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 777 | if (ar.result == null) { |
| 778 | loge("sendEnvelopeWithStatus: Empty response"); |
| 779 | } else if (ar.exception instanceof CommandException) { |
| 780 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 781 | ar.exception); |
| 782 | } else { |
| 783 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 784 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 785 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 786 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 787 | break; |
| 788 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 789 | case CMD_OPEN_CHANNEL: |
| 790 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 791 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 792 | IccLogicalChannelRequest openChannelRequest = |
| 793 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 794 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 795 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 796 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 797 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 798 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 799 | } else { |
| 800 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 801 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 802 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 803 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 804 | break; |
| 805 | |
| 806 | case EVENT_OPEN_CHANNEL_DONE: |
| 807 | ar = (AsyncResult) msg.obj; |
| 808 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 809 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 810 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 811 | int[] result = (int[]) ar.result; |
| 812 | int channelId = result[0]; |
| 813 | byte[] selectResponse = null; |
| 814 | if (result.length > 1) { |
| 815 | selectResponse = new byte[result.length - 1]; |
| 816 | for (int i = 1; i < result.length; ++i) { |
| 817 | selectResponse[i - 1] = (byte) result[i]; |
| 818 | } |
| 819 | } |
| 820 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 821 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 822 | |
| 823 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 824 | if (uiccPort == null) { |
| 825 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 826 | } else { |
| 827 | IccLogicalChannelRequest channelRequest = |
| 828 | (IccLogicalChannelRequest) request.argument; |
| 829 | channelRequest.channel = channelId; |
| 830 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 831 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 832 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 833 | if (ar.result == null) { |
| 834 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 835 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 836 | if (ar.exception != null) { |
| 837 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 838 | } |
| 839 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 840 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 841 | if (ar.exception instanceof CommandException) { |
| 842 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 843 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 844 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 845 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 846 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 847 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 851 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 852 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 853 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 854 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 855 | break; |
| 856 | |
| 857 | case CMD_CLOSE_CHANNEL: |
| 858 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 859 | uiccPort = getUiccPortFromRequest(request); |
| 860 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 861 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 862 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 863 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 864 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 865 | } else { |
| 866 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 867 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 868 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 869 | break; |
| 870 | |
| 871 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 872 | ar = (AsyncResult) msg.obj; |
| 873 | request = (MainThreadRequest) ar.userObj; |
| 874 | if (ar.exception == null) { |
| 875 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 876 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 877 | if (uiccPort == null) { |
| 878 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 879 | } else { |
| 880 | final int channelId = (Integer) request.argument; |
| 881 | uiccPort.onLogicalChannelClosed(channelId); |
| 882 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 883 | } else { |
| 884 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 885 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 886 | if (ar.exception instanceof CommandException) { |
| 887 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 888 | CommandException.Error error = |
| 889 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 890 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 891 | // should only throw exceptions from the binder threads. |
| 892 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 893 | "iccCloseLogicalChannel: invalid argument "); |
| 894 | } |
| 895 | } else { |
| 896 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 897 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 898 | request.result = (exception != null) ? exception : |
| 899 | new IllegalStateException( |
| 900 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 901 | } |
| 902 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case CMD_NV_READ_ITEM: |
| 906 | request = (MainThreadRequest) msg.obj; |
| 907 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 908 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 909 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 910 | break; |
| 911 | |
| 912 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 913 | ar = (AsyncResult) msg.obj; |
| 914 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 915 | if (ar.exception == null && ar.result != null) { |
| 916 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 917 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 918 | request.result = ""; |
| 919 | if (ar.result == null) { |
| 920 | loge("nvReadItem: Empty response"); |
| 921 | } else if (ar.exception instanceof CommandException) { |
| 922 | loge("nvReadItem: CommandException: " + |
| 923 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 924 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 925 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 926 | } |
| 927 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 928 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 929 | break; |
| 930 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 931 | case CMD_NV_WRITE_ITEM: |
| 932 | request = (MainThreadRequest) msg.obj; |
| 933 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 934 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 935 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 936 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 937 | break; |
| 938 | |
| 939 | case EVENT_NV_WRITE_ITEM_DONE: |
| 940 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 941 | break; |
| 942 | |
| 943 | case CMD_NV_WRITE_CDMA_PRL: |
| 944 | request = (MainThreadRequest) msg.obj; |
| 945 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 946 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 947 | break; |
| 948 | |
| 949 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 950 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 951 | break; |
| 952 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 953 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 954 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 955 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 956 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 957 | break; |
| 958 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 959 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 960 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 961 | break; |
| 962 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 963 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 964 | request = (MainThreadRequest) msg.obj; |
| 965 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 966 | request); |
| 967 | Phone phone = getPhoneFromRequest(request); |
| 968 | if (phone != null) { |
| 969 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 970 | } else { |
| 971 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 972 | request.result = false; |
| 973 | notifyRequester(request); |
| 974 | } |
| 975 | break; |
| 976 | } |
| 977 | |
| 978 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 979 | ar = (AsyncResult) msg.obj; |
| 980 | request = (MainThreadRequest) ar.userObj; |
| 981 | if (ar.exception == null && ar.result != null) { |
| 982 | request.result = ar.result; |
| 983 | } else { |
| 984 | // request.result must be set to something non-null |
| 985 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 986 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 987 | request.result = ar.result; |
| 988 | } else { |
| 989 | request.result = false; |
| 990 | } |
| 991 | if (ar.result == null) { |
| 992 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 993 | } else if (ar.exception instanceof CommandException) { |
| 994 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 995 | + ar.exception); |
| 996 | } else { |
| 997 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 998 | } |
| 999 | } |
| 1000 | notifyRequester(request); |
| 1001 | break; |
| 1002 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1003 | case CMD_IS_VONR_ENABLED: { |
| 1004 | request = (MainThreadRequest) msg.obj; |
| 1005 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1006 | request); |
| 1007 | Phone phone = getPhoneFromRequest(request); |
| 1008 | if (phone != null) { |
| 1009 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1010 | } else { |
| 1011 | loge("isVoNrEnabled: No phone object"); |
| 1012 | request.result = false; |
| 1013 | notifyRequester(request); |
| 1014 | } |
| 1015 | break; |
| 1016 | } |
| 1017 | |
| 1018 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1019 | ar = (AsyncResult) msg.obj; |
| 1020 | request = (MainThreadRequest) ar.userObj; |
| 1021 | if (ar.exception == null && ar.result != null) { |
| 1022 | request.result = ar.result; |
| 1023 | } else { |
| 1024 | // request.result must be set to something non-null |
| 1025 | // for the calling thread to unblock |
| 1026 | if (ar.result != null) { |
| 1027 | request.result = ar.result; |
| 1028 | } else { |
| 1029 | request.result = false; |
| 1030 | } |
| 1031 | if (ar.result == null) { |
| 1032 | loge("isVoNrEnabled: Empty response"); |
| 1033 | } else if (ar.exception instanceof CommandException) { |
| 1034 | loge("isVoNrEnabled: CommandException: " |
| 1035 | + ar.exception); |
| 1036 | } else { |
| 1037 | loge("isVoNrEnabled: Unknown exception"); |
| 1038 | } |
| 1039 | } |
| 1040 | notifyRequester(request); |
| 1041 | break; |
| 1042 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1043 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1044 | request = (MainThreadRequest) msg.obj; |
| 1045 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1046 | Phone phone = getPhoneFromRequest(request); |
| 1047 | if (phone != null) { |
| 1048 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1049 | request.workSource); |
| 1050 | } else { |
| 1051 | loge("enableNrDualConnectivity: No phone object"); |
| 1052 | request.result = |
| 1053 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1054 | notifyRequester(request); |
| 1055 | } |
| 1056 | break; |
| 1057 | } |
| 1058 | |
| 1059 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1060 | ar = (AsyncResult) msg.obj; |
| 1061 | request = (MainThreadRequest) ar.userObj; |
| 1062 | if (ar.exception == null) { |
| 1063 | request.result = |
| 1064 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1065 | } else { |
| 1066 | request.result = |
| 1067 | TelephonyManager |
| 1068 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1069 | if (ar.exception instanceof CommandException) { |
| 1070 | CommandException.Error error = |
| 1071 | ((CommandException) (ar.exception)).getCommandError(); |
| 1072 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1073 | request.result = |
| 1074 | TelephonyManager |
| 1075 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1076 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1077 | request.result = |
| 1078 | TelephonyManager |
| 1079 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1080 | } |
| 1081 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1082 | + ar.exception); |
| 1083 | } else { |
| 1084 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1085 | } |
| 1086 | } |
| 1087 | notifyRequester(request); |
| 1088 | break; |
| 1089 | } |
| 1090 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1091 | case CMD_ENABLE_VONR: { |
| 1092 | request = (MainThreadRequest) msg.obj; |
| 1093 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1094 | Phone phone = getPhoneFromRequest(request); |
| 1095 | if (phone != null) { |
| 1096 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1097 | request.workSource); |
| 1098 | } else { |
| 1099 | loge("setVoNrEnabled: No phone object"); |
| 1100 | request.result = |
| 1101 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1102 | notifyRequester(request); |
| 1103 | } |
| 1104 | break; |
| 1105 | } |
| 1106 | |
| 1107 | case EVENT_ENABLE_VONR_DONE: { |
| 1108 | ar = (AsyncResult) msg.obj; |
| 1109 | request = (MainThreadRequest) ar.userObj; |
| 1110 | if (ar.exception == null) { |
| 1111 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1112 | } else { |
| 1113 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1114 | if (ar.exception instanceof CommandException) { |
| 1115 | CommandException.Error error = |
| 1116 | ((CommandException) (ar.exception)).getCommandError(); |
| 1117 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1118 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1119 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1120 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1121 | } else { |
| 1122 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1123 | } |
| 1124 | loge("setVoNrEnabled" + ": CommandException: " |
| 1125 | + ar.exception); |
| 1126 | } else { |
| 1127 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1128 | } |
| 1129 | } |
| 1130 | notifyRequester(request); |
| 1131 | break; |
| 1132 | } |
| 1133 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1134 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1135 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1136 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1137 | request); |
| 1138 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1139 | break; |
| 1140 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1141 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1142 | ar = (AsyncResult) msg.obj; |
| 1143 | request = (MainThreadRequest) ar.userObj; |
| 1144 | if (ar.exception == null && ar.result != null) { |
| 1145 | request.result = ar.result; // Integer |
| 1146 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1147 | // request.result must be set to something non-null |
| 1148 | // for the calling thread to unblock |
| 1149 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1150 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1151 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1152 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1153 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1154 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1155 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1156 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1157 | } |
| 1158 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1159 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1160 | break; |
| 1161 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1162 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1163 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1164 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1165 | request); |
| 1166 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1167 | (Pair<Integer, Long>) request.argument; |
| 1168 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1169 | reasonWithNetworkTypes.first, |
| 1170 | reasonWithNetworkTypes.second, |
| 1171 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1172 | break; |
| 1173 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1174 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1175 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1176 | break; |
| 1177 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1178 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1179 | request = (MainThreadRequest) msg.obj; |
| 1180 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1181 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1182 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1183 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1184 | break; |
| 1185 | |
| 1186 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1187 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1188 | break; |
| 1189 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1190 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1191 | request = (MainThreadRequest) msg.obj; |
| 1192 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1193 | request); |
| 1194 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1195 | break; |
| 1196 | |
| 1197 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1198 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1199 | break; |
| 1200 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1201 | case CMD_PERFORM_NETWORK_SCAN: |
| 1202 | request = (MainThreadRequest) msg.obj; |
| 1203 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1204 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1205 | break; |
| 1206 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1207 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | request = (MainThreadRequest) msg.obj; |
| 1209 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1210 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1211 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1212 | request.argument; |
| 1213 | int callForwardingReason = args.first; |
| 1214 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1215 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | } |
| 1217 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | ar = (AsyncResult) msg.obj; |
| 1219 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1220 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1221 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1222 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1226 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1227 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1228 | // any service for voice call. |
| 1229 | if ((callForwardInfo.serviceClass |
| 1230 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1231 | callForwardingInfo = new CallForwardingInfo( |
| 1232 | callForwardInfo.status |
| 1233 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1234 | callForwardInfo.reason, |
| 1235 | callForwardInfo.number, |
| 1236 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | break; |
| 1238 | } |
| 1239 | } |
| 1240 | // Didn't find a call forward info for voice call. |
| 1241 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1243 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1245 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | } else { |
| 1247 | if (ar.result == null) { |
| 1248 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1249 | } |
| 1250 | if (ar.exception != null) { |
| 1251 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1252 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1253 | int errorCode = TelephonyManager |
| 1254 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | if (ar.exception instanceof CommandException) { |
| 1256 | CommandException.Error error = |
| 1257 | ((CommandException) (ar.exception)).getCommandError(); |
| 1258 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1259 | errorCode = TelephonyManager |
| 1260 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1262 | errorCode = TelephonyManager |
| 1263 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | } |
| 1265 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1266 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | request = (MainThreadRequest) msg.obj; |
| 1273 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1277 | request.argument).first; |
| 1278 | request.phone.setCallForwardingOption( |
| 1279 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1280 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | callForwardingInfoToSet.getReason(), |
| 1283 | callForwardingInfoToSet.getNumber(), |
| 1284 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1285 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1287 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1288 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | ar = (AsyncResult) msg.obj; |
| 1290 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | Consumer<Integer> callback = |
| 1292 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1293 | request.argument).second; |
| 1294 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1296 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1297 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | if (ar.exception instanceof CommandException) { |
| 1299 | CommandException.Error error = |
| 1300 | ((CommandException) (ar.exception)).getCommandError(); |
| 1301 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1302 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1303 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1305 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1306 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | callback.accept(errorCode); |
| 1310 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1311 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | request = (MainThreadRequest) msg.obj; |
| 1318 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1319 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1320 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1321 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1323 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | ar = (AsyncResult) msg.obj; |
| 1325 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1326 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1327 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1328 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1329 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | // Service Class is a bit mask per 3gpp 27.007. |
| 1331 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1332 | if (callForwardResults.length > 1 |
| 1333 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1335 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1336 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1337 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1339 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | } |
| 1341 | } else { |
| 1342 | if (ar.result == null) { |
| 1343 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1344 | } |
| 1345 | if (ar.exception != null) { |
| 1346 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1347 | } |
| 1348 | if (ar.exception instanceof CommandException) { |
| 1349 | CommandException.Error error = |
| 1350 | ((CommandException) (ar.exception)).getCommandError(); |
| 1351 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1352 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1353 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1354 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1355 | callWaitingStatus = |
| 1356 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1357 | } |
| 1358 | } |
| 1359 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1360 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1361 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1362 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1363 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1364 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1365 | request = (MainThreadRequest) msg.obj; |
| 1366 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1367 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1368 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1369 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1370 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1371 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1372 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1373 | ar = (AsyncResult) msg.obj; |
| 1374 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1375 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1376 | Consumer<Integer> callback = |
| 1377 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1378 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1379 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1380 | if (ar.exception instanceof CommandException) { |
| 1381 | CommandException.Error error = |
| 1382 | ((CommandException) (ar.exception)).getCommandError(); |
| 1383 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1384 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1385 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1386 | callback.accept( |
| 1387 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1388 | } else { |
| 1389 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1390 | } |
| 1391 | } else { |
| 1392 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1393 | } |
| 1394 | } else { |
| 1395 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1396 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1397 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1398 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1399 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1400 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1401 | ar = (AsyncResult) msg.obj; |
| 1402 | request = (MainThreadRequest) ar.userObj; |
| 1403 | CellNetworkScanResult cellScanResult; |
| 1404 | if (ar.exception == null && ar.result != null) { |
| 1405 | cellScanResult = new CellNetworkScanResult( |
| 1406 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1407 | (List<OperatorInfo>) ar.result); |
| 1408 | } else { |
| 1409 | if (ar.result == null) { |
| 1410 | loge("getCellNetworkScanResults: Empty response"); |
| 1411 | } |
| 1412 | if (ar.exception != null) { |
| 1413 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1414 | } |
| 1415 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1416 | if (ar.exception instanceof CommandException) { |
| 1417 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1418 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1419 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1420 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1421 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1422 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1423 | } |
| 1424 | } |
| 1425 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1426 | } |
| 1427 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1428 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1429 | break; |
| 1430 | |
| 1431 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1432 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1433 | ManualNetworkSelectionArgument selArg = |
| 1434 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1435 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1436 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1437 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1438 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1439 | break; |
| 1440 | |
| 1441 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1442 | ar = (AsyncResult) msg.obj; |
| 1443 | request = (MainThreadRequest) ar.userObj; |
| 1444 | if (ar.exception == null) { |
| 1445 | request.result = true; |
| 1446 | } else { |
| 1447 | request.result = false; |
| 1448 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1449 | } |
| 1450 | notifyRequester(request); |
| 1451 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1452 | break; |
| 1453 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1454 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1455 | request = (MainThreadRequest) msg.obj; |
| 1456 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1457 | if (defaultPhone != null) { |
| 1458 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1459 | } else { |
| 1460 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1461 | Bundle bundle = new Bundle(); |
| 1462 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1463 | new ModemActivityInfo(0, 0, 0, |
| 1464 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1466 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1467 | break; |
| 1468 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1469 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1470 | ar = (AsyncResult) msg.obj; |
| 1471 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1472 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1473 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1474 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1475 | if (mLastModemActivityInfo == null) { |
| 1476 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1477 | mLastModemActivitySpecificInfo[0] = |
| 1478 | new ActivityStatsTechSpecificInfo( |
| 1479 | 0, |
| 1480 | 0, |
| 1481 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1482 | 0); |
| 1483 | mLastModemActivityInfo = |
| 1484 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1485 | } |
| 1486 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1487 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1488 | // Update the last modem activity info and the result of the request. |
| 1489 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1490 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1491 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1492 | } else { |
| 1493 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1494 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1495 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1496 | // We don't want to return mLastModemActivityInfo which is updated |
| 1497 | // inside mergeModemActivityInfo() |
| 1498 | ret = new ModemActivityInfo( |
| 1499 | mLastModemActivityInfo.getTimestampMillis(), |
| 1500 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1501 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1502 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1503 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1504 | } else { |
| 1505 | if (ar.result == null) { |
| 1506 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1507 | error = TelephonyManager.ModemActivityInfoException |
| 1508 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1509 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1510 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1511 | error = TelephonyManager.ModemActivityInfoException |
| 1512 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1513 | } else { |
| 1514 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1515 | error = TelephonyManager.ModemActivityInfoException |
| 1516 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1517 | } |
| 1518 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1519 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1520 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1521 | bundle.putParcelable( |
| 1522 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1523 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1524 | } else { |
| 1525 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1526 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1527 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1528 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1529 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1530 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1531 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1532 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1533 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1534 | CarrierRestrictionRules argument = |
| 1535 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1536 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1537 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1538 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1539 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1540 | |
| 1541 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1542 | ar = (AsyncResult) msg.obj; |
| 1543 | request = (MainThreadRequest) ar.userObj; |
| 1544 | if (ar.exception == null && ar.result != null) { |
| 1545 | request.result = ar.result; |
| 1546 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1547 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1548 | if (ar.exception instanceof CommandException) { |
| 1549 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1550 | CommandException.Error error = |
| 1551 | ((CommandException) (ar.exception)).getCommandError(); |
| 1552 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1553 | request.result = |
| 1554 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1555 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1556 | } else { |
| 1557 | loge("setAllowedCarriers: Unknown exception"); |
| 1558 | } |
| 1559 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1560 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1561 | break; |
| 1562 | |
| 1563 | case CMD_GET_ALLOWED_CARRIERS: |
| 1564 | request = (MainThreadRequest) msg.obj; |
| 1565 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1566 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1567 | break; |
| 1568 | |
| 1569 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1570 | ar = (AsyncResult) msg.obj; |
| 1571 | request = (MainThreadRequest) ar.userObj; |
| 1572 | if (ar.exception == null && ar.result != null) { |
| 1573 | request.result = ar.result; |
| 1574 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1575 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1576 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1577 | if (ar.result == null) { |
| 1578 | loge("getAllowedCarriers: Empty response"); |
| 1579 | } else if (ar.exception instanceof CommandException) { |
| 1580 | loge("getAllowedCarriers: CommandException: " + |
| 1581 | ar.exception); |
| 1582 | } else { |
| 1583 | loge("getAllowedCarriers: Unknown exception"); |
| 1584 | } |
| 1585 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1586 | if (request.argument != null) { |
| 1587 | // This is for the implementation of carrierRestrictionStatus. |
| 1588 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1589 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1590 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1591 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1592 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1593 | CarrierRestrictionRules carrierRestrictionRules = |
| 1594 | (CarrierRestrictionRules) ar.result; |
| 1595 | int carrierId = -1; |
| 1596 | try { |
| 1597 | CarrierIdentifier carrierIdentifier = |
| 1598 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1599 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1600 | carrierIdentifier); |
| 1601 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1602 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1603 | } |
| 1604 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1605 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1606 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1607 | lockStatus = TelephonyManager |
| 1608 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1609 | } |
| 1610 | } else { |
| 1611 | Rlog.e(LOG_TAG, |
| 1612 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1613 | } |
| 1614 | callback.accept(lockStatus); |
| 1615 | } else { |
| 1616 | // This is for the implementation of getAllowedCarriers. |
| 1617 | notifyRequester(request); |
| 1618 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1619 | break; |
| 1620 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1621 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1622 | ar = (AsyncResult) msg.obj; |
| 1623 | request = (MainThreadRequest) ar.userObj; |
| 1624 | if (ar.exception == null && ar.result != null) { |
| 1625 | request.result = ar.result; |
| 1626 | } else { |
| 1627 | request.result = new IllegalArgumentException( |
| 1628 | "Failed to retrieve Forbidden Plmns"); |
| 1629 | if (ar.result == null) { |
| 1630 | loge("getForbiddenPlmns: Empty response"); |
| 1631 | } else { |
| 1632 | loge("getForbiddenPlmns: Unknown exception"); |
| 1633 | } |
| 1634 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1635 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1636 | break; |
| 1637 | |
| 1638 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1639 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1640 | uiccPort = getUiccPortFromRequest(request); |
| 1641 | if (uiccPort == null) { |
| 1642 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1643 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1644 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1645 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1646 | break; |
| 1647 | } |
| 1648 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1649 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1650 | if (uiccApp == null) { |
| 1651 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1652 | + appType); |
| 1653 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1654 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1655 | break; |
| 1656 | } else { |
| 1657 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1658 | + " specified type -- " + appType); |
| 1659 | } |
| 1660 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1661 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1662 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1663 | break; |
| 1664 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1665 | case CMD_SWITCH_SLOTS: |
| 1666 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1667 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1668 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1669 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1670 | break; |
| 1671 | |
| 1672 | case EVENT_SWITCH_SLOTS_DONE: |
| 1673 | ar = (AsyncResult) msg.obj; |
| 1674 | request = (MainThreadRequest) ar.userObj; |
| 1675 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1676 | notifyRequester(request); |
| 1677 | break; |
| 1678 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1679 | request = (MainThreadRequest) msg.obj; |
| 1680 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1681 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1682 | break; |
| 1683 | |
| 1684 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1685 | ar = (AsyncResult) msg.obj; |
| 1686 | request = (MainThreadRequest) ar.userObj; |
| 1687 | if (ar.exception != null) { |
| 1688 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1689 | } else { |
| 1690 | int mode = ((int[]) ar.result)[0]; |
| 1691 | if (mode == 0) { |
| 1692 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1693 | } else { |
| 1694 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1695 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1696 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1697 | notifyRequester(request); |
| 1698 | break; |
| 1699 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1700 | request = (MainThreadRequest) msg.obj; |
| 1701 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1702 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1703 | break; |
| 1704 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1705 | ar = (AsyncResult) msg.obj; |
| 1706 | request = (MainThreadRequest) ar.userObj; |
| 1707 | if (ar.exception != null) { |
| 1708 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1709 | } else { |
| 1710 | request.result = ((int[]) ar.result)[0]; |
| 1711 | } |
| 1712 | notifyRequester(request); |
| 1713 | break; |
| 1714 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1715 | request = (MainThreadRequest) msg.obj; |
| 1716 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1717 | int mode = (int) request.argument; |
| 1718 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1719 | break; |
| 1720 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1721 | ar = (AsyncResult) msg.obj; |
| 1722 | request = (MainThreadRequest) ar.userObj; |
| 1723 | request.result = ar.exception == null; |
| 1724 | notifyRequester(request); |
| 1725 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1726 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1727 | request = (MainThreadRequest) msg.obj; |
| 1728 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1729 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1730 | break; |
| 1731 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1732 | ar = (AsyncResult) msg.obj; |
| 1733 | request = (MainThreadRequest) ar.userObj; |
| 1734 | if (ar.exception != null) { |
| 1735 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1736 | } else { |
| 1737 | request.result = ((int[]) ar.result)[0]; |
| 1738 | } |
| 1739 | notifyRequester(request); |
| 1740 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1741 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1742 | request = (MainThreadRequest) msg.obj; |
| 1743 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1744 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1745 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1746 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1747 | break; |
| 1748 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1749 | ar = (AsyncResult) msg.obj; |
| 1750 | request = (MainThreadRequest) ar.userObj; |
| 1751 | request.result = ar.exception == null; |
| 1752 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1753 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1754 | case CMD_GET_ALL_CELL_INFO: |
| 1755 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1756 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1757 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1758 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1759 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1760 | ar = (AsyncResult) msg.obj; |
| 1761 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1762 | // If a timeout occurs, the response will be null |
| 1763 | request.result = (ar.exception == null && ar.result != null) |
| 1764 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1765 | synchronized (request) { |
| 1766 | request.notifyAll(); |
| 1767 | } |
| 1768 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1769 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1770 | request = (MainThreadRequest) msg.obj; |
| 1771 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1772 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1773 | break; |
| 1774 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1775 | ar = (AsyncResult) msg.obj; |
| 1776 | request = (MainThreadRequest) ar.userObj; |
| 1777 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1778 | try { |
| 1779 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1780 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1781 | cb.onError( |
| 1782 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1783 | ar.exception.getClass().getName(), |
| 1784 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1785 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1786 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1787 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1788 | } else { |
| 1789 | // use the result as returned |
| 1790 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1791 | } |
| 1792 | } catch (RemoteException re) { |
| 1793 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1794 | } |
| 1795 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1796 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1797 | request = (MainThreadRequest) msg.obj; |
| 1798 | WorkSource ws = (WorkSource) request.argument; |
| 1799 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1800 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1801 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1802 | } |
| 1803 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1804 | ar = (AsyncResult) msg.obj; |
| 1805 | request = (MainThreadRequest) ar.userObj; |
| 1806 | if (ar.exception == null) { |
| 1807 | request.result = ar.result; |
| 1808 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1809 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1810 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1811 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | synchronized (request) { |
| 1815 | request.notifyAll(); |
| 1816 | } |
| 1817 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1818 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1819 | case CMD_MODEM_REBOOT: |
| 1820 | request = (MainThreadRequest) msg.obj; |
| 1821 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1822 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1823 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1824 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1825 | handleNullReturnEvent(msg, "rebootModem"); |
| 1826 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1827 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1828 | request = (MainThreadRequest) msg.obj; |
| 1829 | boolean enable = (boolean) request.argument; |
| 1830 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1831 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1832 | PhoneConfigurationManager.getInstance() |
| 1833 | .enablePhone(request.phone, enable, onCompleted); |
| 1834 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1835 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1836 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1837 | ar = (AsyncResult) msg.obj; |
| 1838 | request = (MainThreadRequest) ar.userObj; |
| 1839 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1840 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1841 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1842 | if ((boolean) request.result) { |
| 1843 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1844 | updateModemStateMetrics(); |
| 1845 | } else { |
| 1846 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1847 | + ar.exception); |
| 1848 | } |
| 1849 | notifyRequester(request); |
| 1850 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1851 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1852 | case CMD_GET_MODEM_STATUS: |
| 1853 | request = (MainThreadRequest) msg.obj; |
| 1854 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1855 | PhoneConfigurationManager.getInstance() |
| 1856 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1857 | break; |
| 1858 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1859 | ar = (AsyncResult) msg.obj; |
| 1860 | request = (MainThreadRequest) ar.userObj; |
| 1861 | int id = request.phone.getPhoneId(); |
| 1862 | if (ar.exception == null && ar.result != null) { |
| 1863 | request.result = ar.result; |
| 1864 | //update the cache as modem status has changed |
| 1865 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1866 | (boolean) request.result); |
| 1867 | } else { |
| 1868 | // Return true if modem status cannot be retrieved. For most cases, |
| 1869 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1870 | // and disable modem are not supported. Modem is always on. |
| 1871 | // TODO: this should be fixed in R to support a third |
| 1872 | // status UNKNOWN b/131631629 |
| 1873 | request.result = true; |
| 1874 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1875 | + ar.exception); |
| 1876 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1877 | notifyRequester(request); |
| 1878 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1879 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1880 | request = (MainThreadRequest) msg.obj; |
| 1881 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1882 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1883 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1884 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1885 | break; |
| 1886 | } |
| 1887 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1888 | ar = (AsyncResult) msg.obj; |
| 1889 | request = (MainThreadRequest) ar.userObj; |
| 1890 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1891 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1892 | args.second.accept(ar.exception == null); |
| 1893 | notifyRequester(request); |
| 1894 | break; |
| 1895 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1896 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1897 | request = (MainThreadRequest) msg.obj; |
| 1898 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1899 | Phone phone = getPhoneFromRequest(request); |
| 1900 | if (phone != null) { |
| 1901 | phone.getSystemSelectionChannels(onCompleted); |
| 1902 | } else { |
| 1903 | loge("getSystemSelectionChannels: No phone object"); |
| 1904 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1905 | notifyRequester(request); |
| 1906 | } |
| 1907 | break; |
| 1908 | } |
| 1909 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1910 | ar = (AsyncResult) msg.obj; |
| 1911 | request = (MainThreadRequest) ar.userObj; |
| 1912 | if (ar.exception == null && ar.result != null) { |
| 1913 | request.result = ar.result; |
| 1914 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1915 | request.result = new IllegalStateException( |
| 1916 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1917 | if (ar.result == null) { |
| 1918 | loge("getSystemSelectionChannels: Empty response"); |
| 1919 | } else { |
| 1920 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1921 | } |
| 1922 | } |
| 1923 | notifyRequester(request); |
| 1924 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1925 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1926 | ar = (AsyncResult) msg.obj; |
| 1927 | request = (MainThreadRequest) ar.userObj; |
| 1928 | if (ar.exception == null && ar.result != null) { |
| 1929 | request.result = ar.result; |
| 1930 | } else { |
| 1931 | request.result = -1; |
| 1932 | loge("Failed to set Forbidden Plmns"); |
| 1933 | if (ar.result == null) { |
| 1934 | loge("setForbidenPlmns: Empty response"); |
| 1935 | } else if (ar.exception != null) { |
| 1936 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1937 | request.result = -1; |
| 1938 | } else { |
| 1939 | loge("setForbiddenPlmns: Unknown exception"); |
| 1940 | } |
| 1941 | } |
| 1942 | notifyRequester(request); |
| 1943 | break; |
| 1944 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1945 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1946 | uiccPort = getUiccPortFromRequest(request); |
| 1947 | if (uiccPort == null) { |
| 1948 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1949 | request.result = -1; |
| 1950 | notifyRequester(request); |
| 1951 | break; |
| 1952 | } |
| 1953 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1954 | (Pair<Integer, List<String>>) request.argument; |
| 1955 | appType = setFplmnsArgs.first; |
| 1956 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1957 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1958 | if (uiccApp == null) { |
| 1959 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1960 | request.result = -1; |
| 1961 | loge("Failed to get UICC App"); |
| 1962 | notifyRequester(request); |
| 1963 | } else { |
| 1964 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1965 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1966 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1967 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1968 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1969 | case CMD_ERASE_MODEM_CONFIG: |
| 1970 | request = (MainThreadRequest) msg.obj; |
| 1971 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1972 | defaultPhone.eraseModemConfig(onCompleted); |
| 1973 | break; |
| 1974 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1975 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1976 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1977 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1978 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1979 | request = (MainThreadRequest) msg.obj; |
| 1980 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1981 | notifyRequester(request); |
| 1982 | break; |
| 1983 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1984 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1985 | request = (MainThreadRequest) msg.obj; |
| 1986 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1987 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1988 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1989 | changed.first, changed.second, onCompleted); |
| 1990 | break; |
| 1991 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1992 | ar = (AsyncResult) msg.obj; |
| 1993 | request = (MainThreadRequest) ar.userObj; |
| 1994 | if (ar.exception == null) { |
| 1995 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1996 | // If the operation is successful, update the PIN storage |
| 1997 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1998 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1999 | UiccController.getInstance().getPinStorage() |
| 2000 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2001 | } else { |
| 2002 | request.result = msg.arg1; |
| 2003 | } |
| 2004 | notifyRequester(request); |
| 2005 | break; |
| 2006 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2007 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2008 | request = (MainThreadRequest) msg.obj; |
| 2009 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2010 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2011 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2012 | enabled.first, enabled.second, onCompleted); |
| 2013 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2014 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2015 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2016 | ar = (AsyncResult) msg.obj; |
| 2017 | request = (MainThreadRequest) ar.userObj; |
| 2018 | if (ar.exception == null) { |
| 2019 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2020 | // If the operation is successful, update the PIN storage |
| 2021 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2022 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2023 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2024 | UiccController.getInstance().getPinStorage() |
| 2025 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2026 | } else { |
| 2027 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2028 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2029 | } else { |
| 2030 | request.result = msg.arg1; |
| 2031 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2032 | |
| 2033 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2034 | notifyRequester(request); |
| 2035 | break; |
| 2036 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2037 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2038 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2039 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2040 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2041 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2042 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2043 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2044 | |
| 2045 | case CMD_SET_DATA_THROTTLING: { |
| 2046 | request = (MainThreadRequest) msg.obj; |
| 2047 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2048 | DataThrottlingRequest dataThrottlingRequest = |
| 2049 | (DataThrottlingRequest) request.argument; |
| 2050 | Phone phone = getPhoneFromRequest(request); |
| 2051 | if (phone != null) { |
| 2052 | phone.setDataThrottling(onCompleted, |
| 2053 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2054 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2055 | } else { |
| 2056 | loge("setDataThrottling: No phone object"); |
| 2057 | request.result = |
| 2058 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2059 | notifyRequester(request); |
| 2060 | } |
| 2061 | |
| 2062 | break; |
| 2063 | } |
| 2064 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2065 | ar = (AsyncResult) msg.obj; |
| 2066 | request = (MainThreadRequest) ar.userObj; |
| 2067 | |
| 2068 | if (ar.exception == null) { |
| 2069 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2070 | } else if (ar.exception instanceof CommandException) { |
| 2071 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2072 | CommandException.Error error = |
| 2073 | ((CommandException) (ar.exception)).getCommandError(); |
| 2074 | |
| 2075 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2076 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2077 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2078 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2079 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2080 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2081 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2082 | } else { |
| 2083 | request.result = |
| 2084 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2085 | } |
| 2086 | } else { |
| 2087 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2088 | } |
| 2089 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2090 | notifyRequester(request); |
| 2091 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2092 | |
| 2093 | case CMD_SET_SIM_POWER: { |
| 2094 | request = (MainThreadRequest) msg.obj; |
| 2095 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2096 | request = (MainThreadRequest) msg.obj; |
| 2097 | int stateToSet = |
| 2098 | ((Pair<Integer, IIntegerConsumer>) |
| 2099 | request.argument).first; |
| 2100 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2101 | break; |
| 2102 | } |
| 2103 | case EVENT_SET_SIM_POWER_DONE: { |
| 2104 | ar = (AsyncResult) msg.obj; |
| 2105 | request = (MainThreadRequest) ar.userObj; |
| 2106 | IIntegerConsumer callback = |
| 2107 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2108 | if (ar.exception != null) { |
| 2109 | loge("setSimPower exception: " + ar.exception); |
| 2110 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2111 | .RESULT_ERROR_UNKNOWN; |
| 2112 | if (ar.exception instanceof CommandException) { |
| 2113 | CommandException.Error error = |
| 2114 | ((CommandException) (ar.exception)).getCommandError(); |
| 2115 | if (error == CommandException.Error.SIM_ERR) { |
| 2116 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2117 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2118 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2119 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2120 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2121 | } else { |
| 2122 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2123 | } |
| 2124 | } |
| 2125 | try { |
| 2126 | callback.accept(errorCode); |
| 2127 | } catch (RemoteException e) { |
| 2128 | // Ignore if the remote process is no longer available to call back. |
| 2129 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2130 | } |
| 2131 | } else { |
| 2132 | try { |
| 2133 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2134 | } catch (RemoteException e) { |
| 2135 | // Ignore if the remote process is no longer available to call back. |
| 2136 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2137 | } |
| 2138 | } |
| 2139 | break; |
| 2140 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2141 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2142 | request = (MainThreadRequest) msg.obj; |
| 2143 | |
| 2144 | final Phone phone = getPhoneFromRequest(request); |
| 2145 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2146 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2147 | notifyRequester(request); |
| 2148 | break; |
| 2149 | } |
| 2150 | |
| 2151 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2152 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2153 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2154 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2155 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2156 | request.subId, pair.first /*callingUid*/, |
| 2157 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2158 | break; |
| 2159 | } |
| 2160 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2161 | ar = (AsyncResult) msg.obj; |
| 2162 | request = (MainThreadRequest) ar.userObj; |
| 2163 | // request.result will be the exception of ar if present, true otherwise. |
| 2164 | // Be cautious not to leave result null which will wait() forever |
| 2165 | request.result = ar.exception != null ? ar.exception : true; |
| 2166 | notifyRequester(request); |
| 2167 | break; |
| 2168 | } |
| 2169 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2170 | request = (MainThreadRequest) msg.obj; |
| 2171 | |
| 2172 | Phone phone = getPhoneFromRequest(request); |
| 2173 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2174 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2175 | notifyRequester(request); |
| 2176 | break; |
| 2177 | } |
| 2178 | |
| 2179 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2180 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2181 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2182 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2183 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2184 | request.subId, pair.first /*callingUid*/, |
| 2185 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2186 | break; |
| 2187 | } |
| 2188 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2189 | ar = (AsyncResult) msg.obj; |
| 2190 | request = (MainThreadRequest) ar.userObj; |
| 2191 | request.result = ar.exception != null ? ar.exception : true; |
| 2192 | notifyRequester(request); |
| 2193 | break; |
| 2194 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2195 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2196 | case CMD_GET_SLICING_CONFIG: { |
| 2197 | request = (MainThreadRequest) msg.obj; |
| 2198 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2199 | request.phone.getSlicingConfig(onCompleted); |
| 2200 | break; |
| 2201 | } |
| 2202 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2203 | ar = (AsyncResult) msg.obj; |
| 2204 | request = (MainThreadRequest) ar.userObj; |
| 2205 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2206 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2207 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2208 | Bundle bundle = new Bundle(); |
| 2209 | int resultCode = 0; |
| 2210 | if (ar.exception != null) { |
| 2211 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2212 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2213 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2214 | } else if (ar.result == null) { |
| 2215 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2216 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2217 | } else { |
| 2218 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2219 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2220 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2224 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2225 | } |
| 2226 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2227 | result.send(resultCode, bundle); |
| 2228 | notifyRequester(request); |
| 2229 | break; |
| 2230 | } |
| 2231 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2232 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2233 | request = (MainThreadRequest) msg.obj; |
| 2234 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2235 | PurchasePremiumCapabilityArgument arg = |
| 2236 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2237 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2238 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2239 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2241 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2242 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2243 | ar = (AsyncResult) msg.obj; |
| 2244 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2245 | PurchasePremiumCapabilityArgument arg = |
| 2246 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2247 | try { |
| 2248 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2249 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2250 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2251 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2252 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2253 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2254 | } catch (RemoteException e) { |
| 2255 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2256 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2257 | + " failed: " + e; |
| 2258 | if (DBG) log(logStr); |
| 2259 | AnomalyReporter.reportAnomaly( |
| 2260 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2261 | } |
| 2262 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2263 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2264 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2265 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2266 | request = (MainThreadRequest) msg.obj; |
| 2267 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2268 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2269 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2270 | notifyRequester(request); |
| 2271 | break; |
| 2272 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2273 | default: |
| 2274 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2275 | break; |
| 2276 | } |
| 2277 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2278 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2279 | private void notifyRequester(MainThreadRequest request) { |
| 2280 | synchronized (request) { |
| 2281 | request.notifyAll(); |
| 2282 | } |
| 2283 | } |
| 2284 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2285 | private void handleNullReturnEvent(Message msg, String command) { |
| 2286 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2287 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2288 | if (ar.exception == null) { |
| 2289 | request.result = true; |
| 2290 | } else { |
| 2291 | request.result = false; |
| 2292 | if (ar.exception instanceof CommandException) { |
| 2293 | loge(command + ": CommandException: " + ar.exception); |
| 2294 | } else { |
| 2295 | loge(command + ": Unknown exception"); |
| 2296 | } |
| 2297 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2298 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | /** |
| 2303 | * Posts the specified command to be executed on the main thread, |
| 2304 | * waits for the request to complete, and returns the result. |
| 2305 | * @see #sendRequestAsync |
| 2306 | */ |
| 2307 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2308 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2309 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | /** |
| 2313 | * Posts the specified command to be executed on the main thread, |
| 2314 | * waits for the request to complete, and returns the result. |
| 2315 | * @see #sendRequestAsync |
| 2316 | */ |
| 2317 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2318 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2319 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | /** |
| 2323 | * Posts the specified command to be executed on the main thread, |
| 2324 | * waits for the request to complete, and returns the result. |
| 2325 | * @see #sendRequestAsync |
| 2326 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2327 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2328 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2329 | } |
| 2330 | |
| 2331 | /** |
| 2332 | * Posts the specified command to be executed on the main thread, |
| 2333 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2334 | * if not timeout or null otherwise. |
| 2335 | * @see #sendRequestAsync |
| 2336 | */ |
| 2337 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2338 | long timeoutInMs) { |
| 2339 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * Posts the specified command to be executed on the main thread, |
| 2344 | * waits for the request to complete, and returns the result. |
| 2345 | * @see #sendRequestAsync |
| 2346 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2347 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2348 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | /** |
| 2352 | * Posts the specified command to be executed on the main thread, |
| 2353 | * waits for the request to complete, and returns the result. |
| 2354 | * @see #sendRequestAsync |
| 2355 | */ |
| 2356 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2357 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2358 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2362 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2363 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2364 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2365 | * @see #sendRequestAsync |
| 2366 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2367 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2368 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2370 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2371 | } |
| 2372 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2373 | MainThreadRequest request = null; |
| 2374 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2375 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2376 | } else if (phone != null) { |
| 2377 | request = new MainThreadRequest(argument, phone, workSource); |
| 2378 | } else { |
| 2379 | request = new MainThreadRequest(argument, subId, workSource); |
| 2380 | } |
| 2381 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2382 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2383 | msg.sendToTarget(); |
| 2384 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2386 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2387 | if (timeoutInMs >= 0) { |
| 2388 | // Wait for at least timeoutInMs before returning null request result |
| 2389 | long now = SystemClock.elapsedRealtime(); |
| 2390 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2391 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2392 | try { |
| 2393 | request.wait(deadline - now); |
| 2394 | } catch (InterruptedException e) { |
| 2395 | // Do nothing, go back and check if request is completed or timeout |
| 2396 | } finally { |
| 2397 | now = SystemClock.elapsedRealtime(); |
| 2398 | } |
| 2399 | } |
| 2400 | } else { |
| 2401 | // Wait for the request to complete |
| 2402 | while (request.result == null) { |
| 2403 | try { |
| 2404 | request.wait(); |
| 2405 | } catch (InterruptedException e) { |
| 2406 | // Do nothing, go back and wait until the request is complete |
| 2407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2411 | if (request.result == null) { |
| 2412 | Log.wtf(LOG_TAG, |
| 2413 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2414 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | return request.result; |
| 2416 | } |
| 2417 | |
| 2418 | /** |
| 2419 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2420 | * Posts the specified command to be executed on the main thread, and |
| 2421 | * returns immediately. |
| 2422 | * @see #sendRequest |
| 2423 | */ |
| 2424 | private void sendRequestAsync(int command) { |
| 2425 | mMainThreadHandler.sendEmptyMessage(command); |
| 2426 | } |
| 2427 | |
| 2428 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2429 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2430 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2431 | */ |
| 2432 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2433 | sendRequestAsync(command, argument, null, null); |
| 2434 | } |
| 2435 | |
| 2436 | /** |
| 2437 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2438 | * @see {@link #sendRequest(int,Object)} |
| 2439 | */ |
| 2440 | private void sendRequestAsync( |
| 2441 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2442 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2443 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2444 | msg.sendToTarget(); |
| 2445 | } |
| 2446 | |
| 2447 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2449 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2450 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2451 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | synchronized (PhoneInterfaceManager.class) { |
| 2453 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2454 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | } else { |
| 2456 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2457 | } |
| 2458 | return sInstance; |
| 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2463 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2465 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2467 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2468 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2469 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2471 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2472 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2473 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2474 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2475 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2476 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2477 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2478 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2479 | getDefaultPhone().getContext(), featureFlags); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2480 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2482 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2483 | |
| 2484 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2485 | // entitlementStatus for satellite service. |
| 2486 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2489 | @VisibleForTesting |
| 2490 | public SharedPreferences getSharedPreferences() { |
| 2491 | return mTelephonySharedPreferences; |
| 2492 | } |
| 2493 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2494 | /** |
| 2495 | * Get the default phone for this device. |
| 2496 | */ |
| 2497 | @VisibleForTesting |
| 2498 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2499 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2500 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2501 | } |
| 2502 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2503 | private void publish() { |
| 2504 | if (DBG) log("publish: " + this); |
| 2505 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2506 | TelephonyFrameworkInitializer |
| 2507 | .getTelephonyServiceManager() |
| 2508 | .getTelephonyServiceRegisterer() |
| 2509 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2512 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2513 | if (request.phone != null) { |
| 2514 | return request.phone; |
| 2515 | } else { |
| 2516 | return getPhoneFromSubId(request.subId); |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | private Phone getPhoneFromSubId(int subId) { |
| 2521 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2522 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2523 | } |
| 2524 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2525 | /** |
| 2526 | * Get phone object associated with a subscription. |
| 2527 | * Return default phone if phone object associated with subscription is null |
| 2528 | * @param subId - subscriptionId |
| 2529 | * @return phone object associated with a subscription or default phone if null. |
| 2530 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2531 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2532 | Phone phone = getPhoneFromSubId(subId); |
| 2533 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2534 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2535 | phone = getDefaultPhone(); |
| 2536 | } |
| 2537 | return phone; |
| 2538 | } |
| 2539 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2540 | @Nullable |
| 2541 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2542 | Phone phone = getPhoneFromRequest(request); |
| 2543 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2544 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2545 | } |
| 2546 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2547 | /** |
| 2548 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2549 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2550 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2551 | * @return The Phone associated the sub Id |
| 2552 | */ |
| 2553 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2554 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2555 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2556 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2557 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2558 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2559 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2560 | } |
| 2561 | |
| 2562 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2563 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2564 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2567 | private boolean isImsAvailableOnDevice() { |
| 2568 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2569 | if (pm == null) { |
| 2570 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2571 | // so do not throw error and allow. |
| 2572 | return true; |
| 2573 | } |
| 2574 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2575 | } |
| 2576 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2578 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2579 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2580 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2581 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2584 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2585 | if (DBG) log("dial: " + number); |
| 2586 | // No permission check needed here: This is just a wrapper around the |
| 2587 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2588 | // the UI before it does anything. |
| 2589 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | final long identity = Binder.clearCallingIdentity(); |
| 2591 | try { |
| 2592 | String url = createTelUrl(number); |
| 2593 | if (url == null) { |
| 2594 | return; |
| 2595 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2596 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2598 | PhoneConstants.State state = mCM.getState(subId); |
| 2599 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2600 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2601 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2602 | mApp.startActivity(intent); |
| 2603 | } |
| 2604 | } finally { |
| 2605 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2610 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2611 | } |
| 2612 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2613 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2614 | if (DBG) log("call: " + number); |
| 2615 | |
| 2616 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2617 | // need to do a permission check since we're calling startActivity() |
| 2618 | // from the context of the phone app. |
| 2619 | enforceCallPermission(); |
| 2620 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2621 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | != AppOpsManager.MODE_ALLOWED) { |
| 2623 | return; |
| 2624 | } |
| 2625 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2626 | enforceTelephonyFeatureWithException(callingPackage, |
| 2627 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2628 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | final long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | String url = createTelUrl(number); |
| 2632 | if (url == null) { |
| 2633 | return; |
| 2634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | boolean isValid = false; |
| 2637 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2638 | if (slist != null) { |
| 2639 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2640 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2641 | isValid = true; |
| 2642 | break; |
| 2643 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2644 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2645 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | if (!isValid) { |
| 2647 | return; |
| 2648 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2651 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2652 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2653 | mApp.startActivity(intent); |
| 2654 | } finally { |
| 2655 | Binder.restoreCallingIdentity(identity); |
| 2656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2659 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2660 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2661 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2662 | } |
| 2663 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2664 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2665 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2666 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2667 | } |
| 2668 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2669 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2672 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2673 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2674 | "supplyPinReportResultForSubscriber"); |
| 2675 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | final long identity = Binder.clearCallingIdentity(); |
| 2677 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2678 | Phone phone = getPhone(subId); |
| 2679 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | checkSimPin.start(); |
| 2681 | return checkSimPin.unlockSim(null, pin); |
| 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(identity); |
| 2684 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2687 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2688 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2689 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2690 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2691 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2692 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | final long identity = Binder.clearCallingIdentity(); |
| 2694 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2695 | Phone phone = getPhone(subId); |
| 2696 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | checkSimPuk.start(); |
| 2698 | return checkSimPuk.unlockSim(puk, pin); |
| 2699 | } finally { |
| 2700 | Binder.restoreCallingIdentity(identity); |
| 2701 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2705 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2706 | * a synchronous one. |
| 2707 | */ |
| 2708 | private static class UnlockSim extends Thread { |
| 2709 | |
| 2710 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2711 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2712 | |
| 2713 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2714 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2715 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | |
| 2717 | // For replies from SimCard interface |
| 2718 | private Handler mHandler; |
| 2719 | |
| 2720 | // For async handler to identify request type |
| 2721 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2722 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2723 | UnlockSim(int phoneId, IccCard simCard) { |
| 2724 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 | mSimCard = simCard; |
| 2726 | } |
| 2727 | |
| 2728 | @Override |
| 2729 | public void run() { |
| 2730 | Looper.prepare(); |
| 2731 | synchronized (UnlockSim.this) { |
| 2732 | mHandler = new Handler() { |
| 2733 | @Override |
| 2734 | public void handleMessage(Message msg) { |
| 2735 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2736 | switch (msg.what) { |
| 2737 | case SUPPLY_PIN_COMPLETE: |
| 2738 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2739 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2740 | mRetryCount = msg.arg1; |
| 2741 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2742 | CommandException.Error error = null; |
| 2743 | if (ar.exception instanceof CommandException) { |
| 2744 | error = ((CommandException) (ar.exception)) |
| 2745 | .getCommandError(); |
| 2746 | } |
| 2747 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2748 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2749 | } else if (error == CommandException.Error.ABORTED) { |
| 2750 | /* When UiccCardApp dispose, handle message and return |
| 2751 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2752 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2753 | } else { |
| 2754 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2755 | } |
| 2756 | } else { |
| 2757 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2758 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | mDone = true; |
| 2760 | UnlockSim.this.notifyAll(); |
| 2761 | } |
| 2762 | break; |
| 2763 | } |
| 2764 | } |
| 2765 | }; |
| 2766 | UnlockSim.this.notifyAll(); |
| 2767 | } |
| 2768 | Looper.loop(); |
| 2769 | } |
| 2770 | |
| 2771 | /* |
| 2772 | * Use PIN or PUK to unlock SIM card |
| 2773 | * |
| 2774 | * If PUK is null, unlock SIM card with PIN |
| 2775 | * |
| 2776 | * 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] | 2777 | * |
| 2778 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2779 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2781 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2782 | |
| 2783 | while (mHandler == null) { |
| 2784 | try { |
| 2785 | wait(); |
| 2786 | } catch (InterruptedException e) { |
| 2787 | Thread.currentThread().interrupt(); |
| 2788 | } |
| 2789 | } |
| 2790 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2791 | |
| 2792 | if (puk == null) { |
| 2793 | mSimCard.supplyPin(pin, callback); |
| 2794 | } else { |
| 2795 | mSimCard.supplyPuk(puk, pin, callback); |
| 2796 | } |
| 2797 | |
| 2798 | while (!mDone) { |
| 2799 | try { |
| 2800 | Log.d(LOG_TAG, "wait for done"); |
| 2801 | wait(); |
| 2802 | } catch (InterruptedException e) { |
| 2803 | // Restore the interrupted status |
| 2804 | Thread.currentThread().interrupt(); |
| 2805 | } |
| 2806 | } |
| 2807 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2808 | int[] resultArray = new int[2]; |
| 2809 | resultArray[0] = mResult; |
| 2810 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2811 | |
| 2812 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2813 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2814 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2815 | // This instance is no longer reused, so quit its thread's looper. |
| 2816 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2817 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2818 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
| 2820 | } |
| 2821 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2822 | /** |
| 2823 | * This method has been removed due to privacy and stability concerns. |
| 2824 | */ |
| 2825 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2826 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2827 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2828 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2831 | @Override |
| 2832 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2833 | mApp.getSystemService(AppOpsManager.class) |
| 2834 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2835 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2836 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2837 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2838 | // Callers targeting S have no business invoking this method. |
| 2839 | return; |
| 2840 | } |
| 2841 | |
| 2842 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2843 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2844 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2845 | .setCallingPackage(callingPackage) |
| 2846 | .setCallingFeatureId(null) |
| 2847 | .setCallingPid(Binder.getCallingPid()) |
| 2848 | .setCallingUid(Binder.getCallingUid()) |
| 2849 | .setMethod("updateServiceLocation") |
| 2850 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2851 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2852 | .build()); |
| 2853 | // Apps that lack location permission have no business calling this method; |
| 2854 | // however, because no permission was declared in the public API, denials must |
| 2855 | // all be "soft". |
| 2856 | switch (locationResult) { |
| 2857 | case DENIED_HARD: /* fall through */ |
| 2858 | case DENIED_SOFT: |
| 2859 | return; |
| 2860 | } |
| 2861 | |
| 2862 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2863 | final long identity = Binder.clearCallingIdentity(); |
| 2864 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2865 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2866 | } finally { |
| 2867 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2868 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2871 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2872 | @Override |
| 2873 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2874 | return isRadioOnWithFeature(callingPackage, null); |
| 2875 | } |
| 2876 | |
| 2877 | |
| 2878 | @Override |
| 2879 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2880 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2881 | callingFeatureId); |
| 2882 | } |
| 2883 | |
| 2884 | @Deprecated |
| 2885 | @Override |
| 2886 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2887 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2890 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2891 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2892 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2894 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2895 | return false; |
| 2896 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2897 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2898 | enforceTelephonyFeatureWithException(callingPackage, |
| 2899 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2900 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | return isRadioOnForSubscriber(subId); |
| 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(identity); |
| 2906 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2910 | final long identity = Binder.clearCallingIdentity(); |
| 2911 | try { |
| 2912 | final Phone phone = getPhone(subId); |
| 2913 | if (phone != null) { |
| 2914 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2915 | } else { |
| 2916 | return false; |
| 2917 | } |
| 2918 | } finally { |
| 2919 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2920 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2924 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2925 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2926 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2927 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2928 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2930 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2931 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2932 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
| 2935 | final Phone phone = getPhone(subId); |
| 2936 | if (phone != null) { |
| 2937 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2938 | } |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2941 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2945 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2948 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2949 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | |
| 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | final Phone phone = getPhone(subId); |
| 2954 | if (phone == null) { |
| 2955 | return false; |
| 2956 | } |
| 2957 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2958 | toggleRadioOnOffForSubscriber(subId); |
| 2959 | } |
| 2960 | return true; |
| 2961 | } finally { |
| 2962 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2963 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2964 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2965 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2966 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2967 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2968 | |
| 2969 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2970 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2971 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2972 | /* |
| 2973 | * If any of the Radios are available, it will need to be |
| 2974 | * shutdown. So return true if any Radio is available. |
| 2975 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | final long identity = Binder.clearCallingIdentity(); |
| 2977 | try { |
| 2978 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2979 | Phone phone = PhoneFactory.getPhone(i); |
| 2980 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2981 | } |
| 2982 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2983 | return false; |
| 2984 | } finally { |
| 2985 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2986 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2989 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2990 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | enforceModifyPermission(); |
| 2992 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2993 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2994 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 2995 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | final long identity = Binder.clearCallingIdentity(); |
| 2997 | try { |
| 2998 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2999 | logv("Shutting down Phone " + i); |
| 3000 | shutdownRadioUsingPhoneId(i); |
| 3001 | } |
| 3002 | } finally { |
| 3003 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3008 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3009 | if (phone != null && phone.isRadioAvailable()) { |
| 3010 | phone.shutdownRadio(); |
| 3011 | } |
| 3012 | } |
| 3013 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3014 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3015 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3016 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3017 | if (!turnOn) { |
| 3018 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3019 | } |
| 3020 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3021 | final long identity = Binder.clearCallingIdentity(); |
| 3022 | try { |
| 3023 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3024 | if (defaultPhone != null) { |
| 3025 | defaultPhone.setRadioPower(turnOn); |
| 3026 | return true; |
| 3027 | } else { |
| 3028 | loge("There's no default phone."); |
| 3029 | return false; |
| 3030 | } |
| 3031 | } finally { |
| 3032 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3033 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3036 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3037 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3038 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3039 | if (!turnOn) { |
| 3040 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3041 | + ",callingPackage=" + getCurrentPackageName()); |
| 3042 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3043 | final long identity = Binder.clearCallingIdentity(); |
| 3044 | try { |
| 3045 | final Phone phone = getPhone(subId); |
| 3046 | if (phone != null) { |
| 3047 | phone.setRadioPower(turnOn); |
| 3048 | return true; |
| 3049 | } else { |
| 3050 | return false; |
| 3051 | } |
| 3052 | } finally { |
| 3053 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3054 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3057 | /** |
| 3058 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3059 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3060 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3061 | * powering it off, and these radio off votes will be cleared. |
| 3062 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3063 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3064 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3065 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3066 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3067 | * check its vote. |
| 3068 | * |
| 3069 | * @param subId The subscription ID. |
| 3070 | * @param reason The reason for powering off radio. |
| 3071 | * @return true on success and false on failure. |
| 3072 | */ |
| 3073 | public boolean requestRadioPowerOffForReason(int subId, |
| 3074 | @TelephonyManager.RadioPowerReason int reason) { |
| 3075 | enforceModifyPermission(); |
| 3076 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3077 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3078 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3079 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3080 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3081 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3084 | boolean result = false; |
| 3085 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3086 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3087 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3088 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3089 | if (!result) { |
| 3090 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3091 | } |
| 3092 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(identity); |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | /** |
| 3099 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3100 | * {@link requestRadioPowerOffForReason}. |
| 3101 | * |
| 3102 | * @param subId The subscription ID. |
| 3103 | * @param reason The reason for powering off radio. |
| 3104 | * @return true on success and false on failure. |
| 3105 | */ |
| 3106 | public boolean clearRadioPowerOffForReason(int subId, |
| 3107 | @TelephonyManager.RadioPowerReason int reason) { |
| 3108 | enforceModifyPermission(); |
| 3109 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3110 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3111 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3112 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3113 | final long identity = Binder.clearCallingIdentity(); |
| 3114 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3115 | boolean result = false; |
| 3116 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3117 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3118 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3119 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3120 | if (!result) { |
| 3121 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3122 | } |
| 3123 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3124 | } finally { |
| 3125 | Binder.restoreCallingIdentity(identity); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | /** |
| 3130 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3131 | * |
| 3132 | * @param subId The subscription ID. |
| 3133 | * @param callingPackage The package making the call. |
| 3134 | * @param callingFeatureId The feature in the package. |
| 3135 | * @return List of reasons for powering off radio. |
| 3136 | */ |
| 3137 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3138 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3139 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3140 | enforceTelephonyFeatureWithException(callingPackage, |
| 3141 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3142 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3143 | final long identity = Binder.clearCallingIdentity(); |
| 3144 | List result = new ArrayList(); |
| 3145 | try { |
| 3146 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3147 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3148 | return result; |
| 3149 | } |
| 3150 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3151 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3152 | if (phone != null) { |
| 3153 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3154 | } else { |
| 3155 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3156 | } |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
| 3159 | } |
| 3160 | return result; |
| 3161 | } |
| 3162 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3163 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3164 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3165 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3166 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3167 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3168 | enforceTelephonyFeatureWithException(callingPackage, |
| 3169 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | final long identity = Binder.clearCallingIdentity(); |
| 3172 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3173 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3174 | final Phone phone = getPhone(subId); |
| 3175 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3176 | phone.getDataSettingsManager().setDataEnabled( |
| 3177 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3178 | return true; |
| 3179 | } else { |
| 3180 | return false; |
| 3181 | } |
| 3182 | } finally { |
| 3183 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3184 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3187 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3188 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3189 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3190 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3191 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3192 | enforceTelephonyFeatureWithException(callingPackage, |
| 3193 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3194 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | final long identity = Binder.clearCallingIdentity(); |
| 3196 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3197 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3198 | final Phone phone = getPhone(subId); |
| 3199 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3200 | phone.getDataSettingsManager().setDataEnabled( |
| 3201 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | return true; |
| 3203 | } else { |
| 3204 | return false; |
| 3205 | } |
| 3206 | } finally { |
| 3207 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3208 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3211 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3212 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3213 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3214 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3216 | final long identity = Binder.clearCallingIdentity(); |
| 3217 | try { |
| 3218 | final Phone phone = getPhone(subId); |
| 3219 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3220 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | } else { |
| 3222 | return false; |
| 3223 | } |
| 3224 | } finally { |
| 3225 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3226 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3230 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3233 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3234 | enforceCallPermission(); |
| 3235 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3236 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3237 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3238 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3239 | final long identity = Binder.clearCallingIdentity(); |
| 3240 | try { |
| 3241 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3242 | return; |
| 3243 | } |
| 3244 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3245 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3246 | } finally { |
| 3247 | Binder.restoreCallingIdentity(identity); |
| 3248 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3249 | }; |
| 3250 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3251 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3252 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3253 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3254 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3255 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3256 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3257 | final long identity = Binder.clearCallingIdentity(); |
| 3258 | try { |
| 3259 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3260 | return false; |
| 3261 | } |
| 3262 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3263 | } finally { |
| 3264 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3265 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3266 | } |
| 3267 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3268 | /** |
| 3269 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3270 | * tag on getCallState Binder call. |
| 3271 | */ |
| 3272 | @Deprecated |
| 3273 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3274 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3275 | if (CompatChanges.isChangeEnabled( |
| 3276 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3277 | Binder.getCallingUid())) { |
| 3278 | // Do not allow this API to be called on API version 31+, it should only be |
| 3279 | // called on old apps using this Binder call directly. |
| 3280 | throw new SecurityException("This method can only be used for applications " |
| 3281 | + "targeting API version 30 or less."); |
| 3282 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3283 | final long identity = Binder.clearCallingIdentity(); |
| 3284 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3285 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3286 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3287 | } finally { |
| 3288 | Binder.restoreCallingIdentity(identity); |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | @Override |
| 3293 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3294 | if (CompatChanges.isChangeEnabled( |
| 3295 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3296 | Binder.getCallingUid())) { |
| 3297 | // Check READ_PHONE_STATE for API version 31+ |
| 3298 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3299 | featureId, "getCallStateForSubscription")) { |
| 3300 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3301 | + "targeting API level 31+."); |
| 3302 | } |
| 3303 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3304 | |
| 3305 | enforceTelephonyFeatureWithException(callingPackage, |
| 3306 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3307 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3308 | final long identity = Binder.clearCallingIdentity(); |
| 3309 | try { |
| 3310 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3312 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3313 | } finally { |
| 3314 | Binder.restoreCallingIdentity(identity); |
| 3315 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3318 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3319 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3320 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | @Override |
| 3324 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3325 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3326 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3327 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3328 | final long identity = Binder.clearCallingIdentity(); |
| 3329 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3330 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3332 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | } else { |
| 3334 | return PhoneConstantConversions.convertDataState( |
| 3335 | PhoneConstants.DataState.DISCONNECTED); |
| 3336 | } |
| 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3339 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3342 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3343 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3344 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3348 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3349 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3350 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3351 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3352 | final long identity = Binder.clearCallingIdentity(); |
| 3353 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3354 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3356 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | } else { |
| 3358 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3359 | } |
| 3360 | } finally { |
| 3361 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3362 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3366 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3367 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3368 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3369 | |
| 3370 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3371 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3372 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3373 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3374 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3375 | .setCallingPid(Binder.getCallingPid()) |
| 3376 | .setCallingUid(Binder.getCallingUid()) |
| 3377 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3378 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3379 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3380 | .build()); |
| 3381 | switch (locationResult) { |
| 3382 | case DENIED_HARD: |
| 3383 | throw new SecurityException("Not allowed to access cell location"); |
| 3384 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3385 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3386 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3389 | enforceTelephonyFeatureWithException(callingPackage, |
| 3390 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3391 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3392 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3393 | final long identity = Binder.clearCallingIdentity(); |
| 3394 | try { |
| 3395 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3396 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3397 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3403 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3404 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3405 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3406 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3407 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3408 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3409 | // registered cell info, so return a NULL country instead. |
| 3410 | final long identity = Binder.clearCallingIdentity(); |
| 3411 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3412 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3413 | // Get default phone in this case. |
| 3414 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3415 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3416 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3417 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3418 | if (phone == null) return ""; |
| 3419 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3420 | if (sst == null) return ""; |
| 3421 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3422 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3423 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(identity); |
| 3426 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3429 | /** |
| 3430 | * This method was removed due to potential issues caused by performing partial |
| 3431 | * updates of service state, and lack of a credible use case. |
| 3432 | * |
| 3433 | * This has the ability to break the telephony implementation by disabling notification of |
| 3434 | * changes in device connectivity. DO NOT USE THIS! |
| 3435 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3436 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3437 | public void enableLocationUpdates() { |
| 3438 | mApp.enforceCallingOrSelfPermission( |
| 3439 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3442 | /** |
| 3443 | * This method was removed due to potential issues caused by performing partial |
| 3444 | * updates of service state, and lack of a credible use case. |
| 3445 | * |
| 3446 | * This has the ability to break the telephony implementation by disabling notification of |
| 3447 | * changes in device connectivity. DO NOT USE THIS! |
| 3448 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3449 | @Override |
| 3450 | public void disableLocationUpdates() { |
| 3451 | mApp.enforceCallingOrSelfPermission( |
| 3452 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | @Override |
| 3456 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3457 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3458 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3459 | try { |
| 3460 | mApp.getSystemService(AppOpsManager.class) |
| 3461 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3462 | } catch (SecurityException e) { |
| 3463 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3464 | throw e; |
| 3465 | } |
| 3466 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3467 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3468 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3469 | throw new SecurityException( |
| 3470 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3471 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3472 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3473 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3474 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3475 | return null; |
| 3476 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3477 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3478 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3479 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3480 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3481 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3482 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3483 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3484 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3485 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3486 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3487 | for (CellInfo ci : info) { |
| 3488 | if (ci instanceof CellInfoGsm) { |
| 3489 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3490 | } else if (ci instanceof CellInfoWcdma) { |
| 3491 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3492 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3493 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3494 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3497 | private List<CellInfo> getCachedCellInfo() { |
| 3498 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3499 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3500 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3501 | if (info != null) cellInfos.addAll(info); |
| 3502 | } |
| 3503 | return cellInfos; |
| 3504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3505 | |
| 3506 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3507 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3508 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3509 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3510 | |
| 3511 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3512 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3513 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3514 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3515 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3516 | .setCallingPid(Binder.getCallingPid()) |
| 3517 | .setCallingUid(Binder.getCallingUid()) |
| 3518 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3519 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3520 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3521 | .build()); |
| 3522 | switch (locationResult) { |
| 3523 | case DENIED_HARD: |
| 3524 | throw new SecurityException("Not allowed to access cell info"); |
| 3525 | case DENIED_SOFT: |
| 3526 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3529 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3530 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3531 | return getCachedCellInfo(); |
| 3532 | } |
| 3533 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3534 | enforceTelephonyFeatureWithException(callingPackage, |
| 3535 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3536 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3537 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3538 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3542 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3543 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3544 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | if (info != null) cellInfos.addAll(info); |
| 3546 | } |
| 3547 | return cellInfos; |
| 3548 | } finally { |
| 3549 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3550 | } |
| 3551 | } |
| 3552 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3553 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3554 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3555 | String callingFeatureId) { |
| 3556 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3557 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3561 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3562 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3563 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3564 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3567 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3568 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3569 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3570 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3571 | |
| 3572 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3573 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3574 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3575 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3576 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3577 | .setCallingPid(Binder.getCallingPid()) |
| 3578 | .setCallingUid(Binder.getCallingUid()) |
| 3579 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3580 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3581 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3582 | .build()); |
| 3583 | switch (locationResult) { |
| 3584 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3585 | if (TelephonyPermissions |
| 3586 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3587 | // Safetynet logging for b/154934934 |
| 3588 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3589 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3590 | throw new SecurityException("Not allowed to access cell info"); |
| 3591 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3592 | if (TelephonyPermissions |
| 3593 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3594 | // Safetynet logging for b/154934934 |
| 3595 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3596 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3597 | try { |
| 3598 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3599 | } catch (RemoteException re) { |
| 3600 | // Drop without consequences |
| 3601 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3602 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3605 | enforceTelephonyFeatureWithException(callingPackage, |
| 3606 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3607 | |
| 3608 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3609 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3610 | |
| 3611 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3612 | } |
| 3613 | |
| 3614 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3615 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3616 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3617 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3618 | |
| 3619 | final long identity = Binder.clearCallingIdentity(); |
| 3620 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3621 | Phone phone = getPhone(subId); |
| 3622 | if (phone == null) { |
| 3623 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3624 | } else { |
| 3625 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3626 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3627 | } finally { |
| 3628 | Binder.restoreCallingIdentity(identity); |
| 3629 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3630 | } |
| 3631 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3632 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3633 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3634 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3635 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3636 | return null; |
| 3637 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3638 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3639 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3640 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3641 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3642 | return null; |
| 3643 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3644 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3645 | enforceTelephonyFeatureWithException(callingPackage, |
| 3646 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | final long identity = Binder.clearCallingIdentity(); |
| 3649 | try { |
| 3650 | return phone.getImei(); |
| 3651 | } finally { |
| 3652 | Binder.restoreCallingIdentity(identity); |
| 3653 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3657 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3658 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3659 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3660 | callingFeatureId, "getPrimaryImei")) { |
| 3661 | throw new SecurityException("Caller does not have permission"); |
| 3662 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3663 | |
| 3664 | enforceTelephonyFeatureWithException(callingPackage, |
| 3665 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3666 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3670 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3671 | return phone.getImei(); |
| 3672 | } |
| 3673 | } |
| 3674 | throw new UnsupportedOperationException("Operation not supported"); |
| 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3681 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3682 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3683 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3684 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3685 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3686 | String tac = null; |
| 3687 | if (phone != null) { |
| 3688 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3689 | try { |
| 3690 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3691 | } catch (IndexOutOfBoundsException e) { |
| 3692 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3693 | return null; |
| 3694 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3695 | } |
| 3696 | return tac; |
| 3697 | } |
| 3698 | |
| 3699 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3700 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3701 | try { |
| 3702 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3703 | } catch (SecurityException se) { |
| 3704 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3705 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3706 | + Binder.getCallingUid()); |
| 3707 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3708 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3709 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3710 | return null; |
| 3711 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3712 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3713 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3714 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3715 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3716 | return null; |
| 3717 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3718 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3719 | enforceTelephonyFeatureWithException(callingPackage, |
| 3720 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3721 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3722 | final long identity = Binder.clearCallingIdentity(); |
| 3723 | try { |
| 3724 | return phone.getMeid(); |
| 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3731 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3732 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3733 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3734 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3735 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3736 | String manufacturerCode = null; |
| 3737 | if (phone != null) { |
| 3738 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3739 | try { |
| 3740 | manufacturerCode = |
| 3741 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3742 | } catch (IndexOutOfBoundsException e) { |
| 3743 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3744 | return null; |
| 3745 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3746 | } |
| 3747 | return manufacturerCode; |
| 3748 | } |
| 3749 | |
| 3750 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3751 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3752 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3753 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3754 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3755 | return null; |
| 3756 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3757 | int subId = phone.getSubId(); |
| 3758 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3759 | mApp, subId, callingPackage, callingFeatureId, |
| 3760 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3761 | return null; |
| 3762 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3763 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3764 | enforceTelephonyFeatureWithException(callingPackage, |
| 3765 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3767 | final long identity = Binder.clearCallingIdentity(); |
| 3768 | try { |
| 3769 | return phone.getDeviceSvn(); |
| 3770 | } finally { |
| 3771 | Binder.restoreCallingIdentity(identity); |
| 3772 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3775 | @Override |
| 3776 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3777 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3778 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3779 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3780 | final long identity = Binder.clearCallingIdentity(); |
| 3781 | try { |
| 3782 | final Phone phone = getPhone(subId); |
| 3783 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3784 | } finally { |
| 3785 | Binder.restoreCallingIdentity(identity); |
| 3786 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | @Override |
| 3790 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3791 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3792 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3793 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | final long identity = Binder.clearCallingIdentity(); |
| 3795 | try { |
| 3796 | final Phone phone = getPhone(subId); |
| 3797 | return phone == null ? null : phone.getCarrierName(); |
| 3798 | } finally { |
| 3799 | Binder.restoreCallingIdentity(identity); |
| 3800 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3801 | } |
| 3802 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3803 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3804 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3805 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3806 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3807 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3808 | final long identity = Binder.clearCallingIdentity(); |
| 3809 | try { |
| 3810 | final Phone phone = getPhone(subId); |
| 3811 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3812 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3813 | } finally { |
| 3814 | Binder.restoreCallingIdentity(identity); |
| 3815 | } |
| 3816 | } |
| 3817 | |
| 3818 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3819 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3820 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3821 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3822 | "getSubscriptionSpecificCarrierName"); |
| 3823 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3824 | final long identity = Binder.clearCallingIdentity(); |
| 3825 | try { |
| 3826 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3827 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(identity); |
| 3830 | } |
| 3831 | } |
| 3832 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3833 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3834 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3835 | if (!isSubscriptionMccMnc) { |
| 3836 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3837 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3838 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3839 | if (phone == null) { |
| 3840 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3841 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3842 | |
| 3843 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3844 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3845 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3846 | final long identity = Binder.clearCallingIdentity(); |
| 3847 | try { |
| 3848 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3849 | } finally { |
| 3850 | Binder.restoreCallingIdentity(identity); |
| 3851 | } |
| 3852 | } |
| 3853 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3854 | // |
| 3855 | // Internal helper methods. |
| 3856 | // |
| 3857 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3858 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3859 | * Make sure the caller is the calling package itself |
| 3860 | * |
| 3861 | * @throws SecurityException if the caller is not the calling package |
| 3862 | */ |
| 3863 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3864 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3865 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3866 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3867 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3868 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3869 | } catch (PackageManager.NameNotFoundException e) { |
| 3870 | // packageUid is -1 |
| 3871 | } |
| 3872 | if (packageUid != callingUid) { |
| 3873 | throw new SecurityException(message + ": Package " + callingPackage |
| 3874 | + " does not belong to " + callingUid); |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3879 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3880 | * |
| 3881 | * @throws SecurityException if the caller does not have the required permission |
| 3882 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3883 | @VisibleForTesting |
| 3884 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3885 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3886 | } |
| 3887 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3888 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3889 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3890 | * |
| 3891 | * @throws SecurityException if the caller does not have the required permission |
| 3892 | */ |
| 3893 | @VisibleForTesting |
| 3894 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3895 | enforceReadPermission(null); |
| 3896 | } |
| 3897 | |
| 3898 | /** |
| 3899 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3900 | * |
| 3901 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3902 | */ |
| 3903 | @VisibleForTesting |
| 3904 | public void enforceReadPermission(String msg) { |
| 3905 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3906 | } |
| 3907 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3908 | private void enforceActiveEmergencySessionPermission() { |
| 3909 | mApp.enforceCallingOrSelfPermission( |
| 3910 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3911 | } |
| 3912 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3913 | /** |
| 3914 | * Make sure the caller has the CALL_PHONE permission. |
| 3915 | * |
| 3916 | * @throws SecurityException if the caller does not have the required permission |
| 3917 | */ |
| 3918 | private void enforceCallPermission() { |
| 3919 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3920 | } |
| 3921 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3922 | private void enforceSettingsPermission() { |
| 3923 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3924 | } |
| 3925 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3926 | private void enforceRebootPermission() { |
| 3927 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3928 | } |
| 3929 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3930 | /** |
| 3931 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3932 | * @param message - log message to print. |
| 3933 | * @throws SecurityException if the caller does not have the required permission |
| 3934 | */ |
| 3935 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3936 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3937 | } |
| 3938 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3939 | private String createTelUrl(String number) { |
| 3940 | if (TextUtils.isEmpty(number)) { |
| 3941 | return null; |
| 3942 | } |
| 3943 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3944 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3947 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3948 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3949 | } |
| 3950 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3951 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3952 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3955 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3956 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3959 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3960 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3961 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3964 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3965 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3966 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3967 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 3968 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | final long identity = Binder.clearCallingIdentity(); |
| 3970 | try { |
| 3971 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3972 | if (phone == null) { |
| 3973 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3974 | } else { |
| 3975 | return phone.getPhoneType(); |
| 3976 | } |
| 3977 | } finally { |
| 3978 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3979 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | /** |
| 3983 | * Returns the CDMA ERI icon index to display |
| 3984 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3985 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3986 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3987 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3988 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3989 | } |
| 3990 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3991 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3992 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3993 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3994 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3995 | mApp, subId, callingPackage, callingFeatureId, |
| 3996 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3997 | return -1; |
| 3998 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3999 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4000 | enforceTelephonyFeatureWithException(callingPackage, |
| 4001 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4002 | "getCdmaEriIconIndexForSubscriber"); |
| 4003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4004 | final long identity = Binder.clearCallingIdentity(); |
| 4005 | try { |
| 4006 | final Phone phone = getPhone(subId); |
| 4007 | if (phone != null) { |
| 4008 | return phone.getCdmaEriIconIndex(); |
| 4009 | } else { |
| 4010 | return -1; |
| 4011 | } |
| 4012 | } finally { |
| 4013 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4014 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * Returns the CDMA ERI icon mode, |
| 4019 | * 0 - ON |
| 4020 | * 1 - FLASHING |
| 4021 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4022 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4023 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4024 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4025 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4028 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4029 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4030 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4031 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4032 | mApp, subId, callingPackage, callingFeatureId, |
| 4033 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4034 | return -1; |
| 4035 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4036 | |
| 4037 | final long identity = Binder.clearCallingIdentity(); |
| 4038 | try { |
| 4039 | final Phone phone = getPhone(subId); |
| 4040 | if (phone != null) { |
| 4041 | return phone.getCdmaEriIconMode(); |
| 4042 | } else { |
| 4043 | return -1; |
| 4044 | } |
| 4045 | } finally { |
| 4046 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4047 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | /** |
| 4051 | * Returns the CDMA ERI text, |
| 4052 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4053 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4054 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4055 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4056 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4059 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4060 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4061 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4062 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4063 | mApp, subId, callingPackage, callingFeatureId, |
| 4064 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4065 | return null; |
| 4066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4067 | |
| 4068 | final long identity = Binder.clearCallingIdentity(); |
| 4069 | try { |
| 4070 | final Phone phone = getPhone(subId); |
| 4071 | if (phone != null) { |
| 4072 | return phone.getCdmaEriText(); |
| 4073 | } else { |
| 4074 | return null; |
| 4075 | } |
| 4076 | } finally { |
| 4077 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4078 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4082 | * Returns the CDMA MDN. |
| 4083 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4084 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4085 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4087 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4088 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4089 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4090 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4091 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | final long identity = Binder.clearCallingIdentity(); |
| 4093 | try { |
| 4094 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4095 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4096 | return phone.getLine1Number(); |
| 4097 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4098 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4099 | return null; |
| 4100 | } |
| 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | /** |
| 4107 | * Returns the CDMA MIN. |
| 4108 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4109 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4110 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4111 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4112 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4113 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4114 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4115 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4116 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4117 | final long identity = Binder.clearCallingIdentity(); |
| 4118 | try { |
| 4119 | final Phone phone = getPhone(subId); |
| 4120 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4121 | return phone.getCdmaMin(); |
| 4122 | } else { |
| 4123 | return null; |
| 4124 | } |
| 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4127 | } |
| 4128 | } |
| 4129 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4130 | @Override |
| 4131 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4132 | INumberVerificationCallback callback, String callingPackage) { |
| 4133 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4134 | != PERMISSION_GRANTED) { |
| 4135 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4136 | } |
| 4137 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4138 | |
| 4139 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4140 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4141 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4142 | + "calling package: " + callingPackage |
| 4143 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4144 | } |
| 4145 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4146 | enforceTelephonyFeatureWithException(callingPackage, |
| 4147 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4148 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4149 | if (range == null) { |
| 4150 | throw new NullPointerException("Range must be non-null"); |
| 4151 | } |
| 4152 | |
| 4153 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4154 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4155 | |
| 4156 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4157 | } |
| 4158 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4159 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4160 | * Returns true if CDMA provisioning needs to run. |
| 4161 | */ |
| 4162 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4163 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4164 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4166 | final long identity = Binder.clearCallingIdentity(); |
| 4167 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4168 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4169 | } finally { |
| 4170 | Binder.restoreCallingIdentity(identity); |
| 4171 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4175 | * Sets the voice mail number of a given subId. |
| 4176 | */ |
| 4177 | @Override |
| 4178 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4179 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4180 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4181 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4182 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4183 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4184 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4185 | final long identity = Binder.clearCallingIdentity(); |
| 4186 | try { |
| 4187 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4188 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4189 | return success; |
| 4190 | } finally { |
| 4191 | Binder.restoreCallingIdentity(identity); |
| 4192 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4193 | } |
| 4194 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4195 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4196 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4197 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4198 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4199 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4200 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4201 | throw new SecurityException("caller must be system dialer"); |
| 4202 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4203 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4204 | enforceTelephonyFeatureWithException(callingPackage, |
| 4205 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4206 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4207 | final long identity = Binder.clearCallingIdentity(); |
| 4208 | try { |
| 4209 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4210 | if (phoneAccountHandle == null) { |
| 4211 | return null; |
| 4212 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4213 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4216 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4220 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4221 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4222 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4224 | mApp, subId, callingPackage, callingFeatureId, |
| 4225 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4226 | return null; |
| 4227 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4228 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4229 | enforceTelephonyFeatureWithException(callingPackage, |
| 4230 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4231 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4232 | final long identity = Binder.clearCallingIdentity(); |
| 4233 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4234 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4235 | } finally { |
| 4236 | Binder.restoreCallingIdentity(identity); |
| 4237 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4241 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4242 | VisualVoicemailSmsFilterSettings settings) { |
| 4243 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4244 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4245 | enforceTelephonyFeatureWithException(callingPackage, |
| 4246 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
| 4247 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 | final long identity = Binder.clearCallingIdentity(); |
| 4249 | try { |
| 4250 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4251 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | } finally { |
| 4253 | Binder.restoreCallingIdentity(identity); |
| 4254 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4258 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4259 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4261 | enforceTelephonyFeatureWithException(callingPackage, |
| 4262 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4263 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4264 | final long identity = Binder.clearCallingIdentity(); |
| 4265 | try { |
| 4266 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4267 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4268 | } finally { |
| 4269 | Binder.restoreCallingIdentity(identity); |
| 4270 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4274 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4275 | String callingPackage, int subId) { |
| 4276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4277 | |
| 4278 | final long identity = Binder.clearCallingIdentity(); |
| 4279 | try { |
| 4280 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4281 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 | } finally { |
| 4283 | Binder.restoreCallingIdentity(identity); |
| 4284 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4288 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4289 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4290 | |
| 4291 | final long identity = Binder.clearCallingIdentity(); |
| 4292 | try { |
| 4293 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4294 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4295 | } finally { |
| 4296 | Binder.restoreCallingIdentity(identity); |
| 4297 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4301 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4302 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4303 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4304 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4305 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4306 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4307 | |
| 4308 | enforceTelephonyFeatureWithException(callingPackage, |
| 4309 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4310 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4311 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4312 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4313 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4314 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4315 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4316 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4317 | * Sets the voice activation state of a given subId. |
| 4318 | */ |
| 4319 | @Override |
| 4320 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4321 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4322 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4323 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4324 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4325 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4326 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4327 | final long identity = Binder.clearCallingIdentity(); |
| 4328 | try { |
| 4329 | final Phone phone = getPhone(subId); |
| 4330 | if (phone != null) { |
| 4331 | phone.setVoiceActivationState(activationState); |
| 4332 | } else { |
| 4333 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4334 | } |
| 4335 | } finally { |
| 4336 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | /** |
| 4341 | * Sets the data activation state of a given subId. |
| 4342 | */ |
| 4343 | @Override |
| 4344 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4346 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4347 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4348 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4349 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4350 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
| 4353 | final Phone phone = getPhone(subId); |
| 4354 | if (phone != null) { |
| 4355 | phone.setDataActivationState(activationState); |
| 4356 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4357 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4358 | } |
| 4359 | } finally { |
| 4360 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4361 | } |
| 4362 | } |
| 4363 | |
| 4364 | /** |
| 4365 | * Returns the voice activation state of a given subId. |
| 4366 | */ |
| 4367 | @Override |
| 4368 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4369 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4370 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4371 | enforceTelephonyFeatureWithException(callingPackage, |
| 4372 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4373 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4374 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4375 | final long identity = Binder.clearCallingIdentity(); |
| 4376 | try { |
| 4377 | if (phone != null) { |
| 4378 | return phone.getVoiceActivationState(); |
| 4379 | } else { |
| 4380 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4381 | } |
| 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | /** |
| 4388 | * Returns the data activation state of a given subId. |
| 4389 | */ |
| 4390 | @Override |
| 4391 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4392 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4393 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4394 | enforceTelephonyFeatureWithException(callingPackage, |
| 4395 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4396 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4397 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4398 | final long identity = Binder.clearCallingIdentity(); |
| 4399 | try { |
| 4400 | if (phone != null) { |
| 4401 | return phone.getDataActivationState(); |
| 4402 | } else { |
| 4403 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4404 | } |
| 4405 | } finally { |
| 4406 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4407 | } |
| 4408 | } |
| 4409 | |
| 4410 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4411 | * Returns the unread count of voicemails for a subId |
| 4412 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4413 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4414 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4415 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4416 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4417 | mApp, subId, callingPackage, callingFeatureId, |
| 4418 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4419 | return 0; |
| 4420 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4421 | final long identity = Binder.clearCallingIdentity(); |
| 4422 | try { |
| 4423 | final Phone phone = getPhone(subId); |
| 4424 | if (phone != null) { |
| 4425 | return phone.getVoiceMessageCount(); |
| 4426 | } else { |
| 4427 | return 0; |
| 4428 | } |
| 4429 | } finally { |
| 4430 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4431 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4435 | * returns true, if the device is in a state where both voice and data |
| 4436 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4437 | */ |
| 4438 | @Override |
| 4439 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4440 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4441 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4445 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4446 | } finally { |
| 4447 | Binder.restoreCallingIdentity(identity); |
| 4448 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4452 | * Send the dialer code if called from the current default dialer or the caller has |
| 4453 | * carrier privilege. |
| 4454 | * @param inputCode The dialer code to send |
| 4455 | */ |
| 4456 | @Override |
| 4457 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4458 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4459 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4460 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4461 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4462 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4463 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4464 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4465 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4466 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4467 | enforceTelephonyFeatureWithException(callingPackage, |
| 4468 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4469 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4470 | final long identity = Binder.clearCallingIdentity(); |
| 4471 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4472 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4473 | } finally { |
| 4474 | Binder.restoreCallingIdentity(identity); |
| 4475 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4476 | } |
| 4477 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4478 | @Override |
| 4479 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4480 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4481 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4482 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4483 | |
| 4484 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4485 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4486 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4487 | final long identity = Binder.clearCallingIdentity(); |
| 4488 | try { |
| 4489 | if (!isActiveSubscription(subId)) { |
| 4490 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4491 | } |
| 4492 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4493 | } finally { |
| 4494 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4495 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4498 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4499 | public boolean isInEmergencySmsMode() { |
| 4500 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4501 | |
| 4502 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4503 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4504 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4505 | final long identity = Binder.clearCallingIdentity(); |
| 4506 | try { |
| 4507 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4508 | if (phone.isInEmergencySmsMode()) { |
| 4509 | return true; |
| 4510 | } |
| 4511 | } |
| 4512 | } finally { |
| 4513 | Binder.restoreCallingIdentity(identity); |
| 4514 | } |
| 4515 | return false; |
| 4516 | } |
| 4517 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4518 | /** |
| 4519 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4520 | * @param subId The subscription to use to check the configuration. |
| 4521 | * @param c The callback that will be used to send the result. |
| 4522 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4523 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4524 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4525 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4526 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4527 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4528 | |
| 4529 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4530 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4531 | "IMS not available on device."); |
| 4532 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4533 | final long token = Binder.clearCallingIdentity(); |
| 4534 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4535 | int slotId = getSlotIndexOrException(subId); |
| 4536 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4537 | |
| 4538 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4539 | if (controller != null) { |
| 4540 | ImsManager imsManager = controller.getImsManager(subId); |
| 4541 | if (imsManager != null) { |
| 4542 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4543 | } else { |
| 4544 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4545 | } |
| 4546 | } else { |
| 4547 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4548 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4549 | } catch (ImsException e) { |
| 4550 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4551 | } finally { |
| 4552 | Binder.restoreCallingIdentity(token); |
| 4553 | } |
| 4554 | } |
| 4555 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4556 | /** |
| 4557 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4558 | * @param subId The subscription to use to check the configuration. |
| 4559 | * @param c The callback that will be used to send the result. |
| 4560 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4561 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4562 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4563 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4564 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4565 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4566 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4567 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4568 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4569 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4570 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4571 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4572 | if (controller != null) { |
| 4573 | ImsManager imsManager = controller.getImsManager(subId); |
| 4574 | if (imsManager != null) { |
| 4575 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4576 | } else { |
| 4577 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4578 | + "is inactive, ignoring unregister."); |
| 4579 | // If the ImsManager is not valid, just return, since the callback |
| 4580 | // will already have been removed internally. |
| 4581 | } |
| 4582 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4583 | } finally { |
| 4584 | Binder.restoreCallingIdentity(token); |
| 4585 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4586 | } |
| 4587 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4588 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4589 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4590 | * @param subId The subscription to use to check the configuration. |
| 4591 | * @param c The callback that will be used to send the result. |
| 4592 | */ |
| 4593 | @Override |
| 4594 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4595 | throws RemoteException { |
| 4596 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4597 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4598 | |
| 4599 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4600 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4601 | "IMS not available on device."); |
| 4602 | } |
| 4603 | final long token = Binder.clearCallingIdentity(); |
| 4604 | try { |
| 4605 | int slotId = getSlotIndexOrException(subId); |
| 4606 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4607 | |
| 4608 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4609 | if (controller != null) { |
| 4610 | ImsManager imsManager = controller.getImsManager(subId); |
| 4611 | if (imsManager != null) { |
| 4612 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4613 | } else { |
| 4614 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4615 | } |
| 4616 | } else { |
| 4617 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4618 | } |
| 4619 | } catch (ImsException e) { |
| 4620 | throw new ServiceSpecificException(e.getCode()); |
| 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(token); |
| 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | /** |
| 4627 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4628 | * @param subId The subscription to use to check the configuration. |
| 4629 | * @param c The callback that will be used to send the result. |
| 4630 | */ |
| 4631 | @Override |
| 4632 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4633 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4634 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4635 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4636 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4637 | } |
| 4638 | final long token = Binder.clearCallingIdentity(); |
| 4639 | |
| 4640 | try { |
| 4641 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4642 | if (controller != null) { |
| 4643 | ImsManager imsManager = controller.getImsManager(subId); |
| 4644 | if (imsManager != null) { |
| 4645 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4646 | } else { |
| 4647 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4648 | + "is inactive, ignoring unregister."); |
| 4649 | // If the ImsManager is not valid, just return, since the callback |
| 4650 | // will already have been removed internally. |
| 4651 | } |
| 4652 | } |
| 4653 | } finally { |
| 4654 | Binder.restoreCallingIdentity(token); |
| 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4659 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4660 | */ |
| 4661 | @Override |
| 4662 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4663 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4664 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4665 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4666 | "IMS not available on device."); |
| 4667 | } |
| 4668 | final long token = Binder.clearCallingIdentity(); |
| 4669 | try { |
| 4670 | Phone phone = getPhone(subId); |
| 4671 | if (phone == null) { |
| 4672 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4673 | + subId + "'"); |
| 4674 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4675 | } |
| 4676 | phone.getImsRegistrationState(regState -> { |
| 4677 | try { |
| 4678 | consumer.accept((regState == null) |
| 4679 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4680 | } catch (RemoteException e) { |
| 4681 | // Ignore if the remote process is no longer available to call back. |
| 4682 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4683 | } |
| 4684 | }); |
| 4685 | } finally { |
| 4686 | Binder.restoreCallingIdentity(token); |
| 4687 | } |
| 4688 | } |
| 4689 | |
| 4690 | /** |
| 4691 | * Get the transport type for the IMS service registration state. |
| 4692 | */ |
| 4693 | @Override |
| 4694 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4695 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4696 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4697 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4698 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4699 | "IMS not available on device."); |
| 4700 | } |
| 4701 | final long token = Binder.clearCallingIdentity(); |
| 4702 | try { |
| 4703 | Phone phone = getPhone(subId); |
| 4704 | if (phone == null) { |
| 4705 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4706 | + subId + "'"); |
| 4707 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4708 | } |
| 4709 | phone.getImsRegistrationTech(regTech -> { |
| 4710 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4711 | int regTechConverted = (regTech == null) |
| 4712 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4713 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4714 | regTechConverted); |
| 4715 | try { |
| 4716 | consumer.accept(regTechConverted); |
| 4717 | } catch (RemoteException e) { |
| 4718 | // Ignore if the remote process is no longer available to call back. |
| 4719 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4720 | } |
| 4721 | }); |
| 4722 | } finally { |
| 4723 | Binder.restoreCallingIdentity(token); |
| 4724 | } |
| 4725 | } |
| 4726 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4727 | /** |
| 4728 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4729 | * @param subId The subscription to use to check the configuration. |
| 4730 | * @param c The callback that will be used to send the result. |
| 4731 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4732 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4733 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4734 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4735 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4736 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4737 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4738 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4739 | "IMS not available on device."); |
| 4740 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4741 | final long token = Binder.clearCallingIdentity(); |
| 4742 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4743 | int slotId = getSlotIndexOrException(subId); |
| 4744 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4745 | |
| 4746 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4747 | if (controller != null) { |
| 4748 | ImsManager imsManager = controller.getImsManager(subId); |
| 4749 | if (imsManager != null) { |
| 4750 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4751 | } else { |
| 4752 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4753 | } |
| 4754 | } else { |
| 4755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4756 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4757 | } catch (ImsException e) { |
| 4758 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4759 | } finally { |
| 4760 | Binder.restoreCallingIdentity(token); |
| 4761 | } |
| 4762 | } |
| 4763 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4764 | /** |
| 4765 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4766 | * @param subId The subscription to use to check the configuration. |
| 4767 | * @param c The callback that will be used to send the result. |
| 4768 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4770 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4771 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4772 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4773 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4774 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4775 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4776 | |
| 4777 | final long token = Binder.clearCallingIdentity(); |
| 4778 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4779 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4780 | if (controller != null) { |
| 4781 | ImsManager imsManager = controller.getImsManager(subId); |
| 4782 | if (imsManager != null) { |
| 4783 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4784 | } else { |
| 4785 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4786 | + " is inactive, ignoring unregister."); |
| 4787 | // If the ImsManager is not valid, just return, since the callback |
| 4788 | // will already have been removed internally. |
| 4789 | } |
| 4790 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4791 | } finally { |
| 4792 | Binder.restoreCallingIdentity(token); |
| 4793 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4797 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4798 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4799 | |
| 4800 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4801 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4802 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4803 | final long token = Binder.clearCallingIdentity(); |
| 4804 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4805 | int slotId = getSlotIndexOrException(subId); |
| 4806 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4807 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4808 | } catch (com.android.ims.ImsException e) { |
| 4809 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4810 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4811 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4812 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4813 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4814 | } finally { |
| 4815 | Binder.restoreCallingIdentity(token); |
| 4816 | } |
| 4817 | } |
| 4818 | |
| 4819 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4820 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4821 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4822 | |
| 4823 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4824 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4825 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4826 | final long token = Binder.clearCallingIdentity(); |
| 4827 | try { |
| 4828 | Phone phone = getPhone(subId); |
| 4829 | if (phone == null) return false; |
| 4830 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4831 | } catch (com.android.ims.ImsException e) { |
| 4832 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4833 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4834 | } finally { |
| 4835 | Binder.restoreCallingIdentity(token); |
| 4836 | } |
| 4837 | } |
| 4838 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4839 | /** |
| 4840 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4841 | * subscription. |
| 4842 | * @param subId The subscription to use to check the configuration. |
| 4843 | * @param callback The callback that will be used to send the result. |
| 4844 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4845 | * @param transportType The transport type of the MmTelFeature capability. |
| 4846 | */ |
| 4847 | @Override |
| 4848 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4849 | int transportType) { |
| 4850 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4851 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4852 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4853 | "IMS not available on device."); |
| 4854 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4855 | final long token = Binder.clearCallingIdentity(); |
| 4856 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4857 | int slotId = getSlotIndex(subId); |
| 4858 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4859 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4860 | + subId + "'"); |
| 4861 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4862 | } |
| 4863 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4864 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4865 | transportType, aBoolean -> { |
| 4866 | try { |
| 4867 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4868 | } catch (RemoteException e) { |
| 4869 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4870 | + "running. Ignore"); |
| 4871 | } |
| 4872 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4873 | } catch (ImsException e) { |
| 4874 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4875 | } finally { |
| 4876 | Binder.restoreCallingIdentity(token); |
| 4877 | } |
| 4878 | } |
| 4879 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4880 | /** |
| 4881 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4882 | * @param subId The subscription to use to check the configuration. |
| 4883 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4884 | @Override |
| 4885 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4886 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4887 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4888 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4889 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4890 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4891 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4892 | final long token = Binder.clearCallingIdentity(); |
| 4893 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4894 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4895 | // 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] | 4896 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4897 | } catch (ImsException e) { |
| 4898 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4899 | } finally { |
| 4900 | Binder.restoreCallingIdentity(token); |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4905 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4907 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4908 | |
| 4909 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4910 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4911 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4912 | final long identity = Binder.clearCallingIdentity(); |
| 4913 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4914 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4915 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4916 | // 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] | 4917 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4918 | } catch (ImsException e) { |
| 4919 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
| 4922 | } |
| 4923 | } |
| 4924 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4925 | /** |
| 4926 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4927 | * @param subId The subscription to use to check the configuration. |
| 4928 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4929 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4930 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4931 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4932 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4933 | |
| 4934 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4935 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4936 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4937 | final long identity = Binder.clearCallingIdentity(); |
| 4938 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4939 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4940 | // 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] | 4941 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4942 | } catch (ImsException e) { |
| 4943 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4944 | } finally { |
| 4945 | Binder.restoreCallingIdentity(identity); |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4950 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4952 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4953 | |
| 4954 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4955 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4956 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4957 | final long identity = Binder.clearCallingIdentity(); |
| 4958 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4959 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4960 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4961 | // 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] | 4962 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4963 | } catch (ImsException e) { |
| 4964 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4965 | } finally { |
| 4966 | Binder.restoreCallingIdentity(identity); |
| 4967 | } |
| 4968 | } |
| 4969 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4970 | /** |
| 4971 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4972 | * @param subId The subscription to use to check the configuration. |
| 4973 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4974 | @Override |
| 4975 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4976 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4977 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4978 | |
| 4979 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4980 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 4981 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4982 | final long identity = Binder.clearCallingIdentity(); |
| 4983 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4984 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4985 | // 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] | 4986 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4987 | } catch (ImsException e) { |
| 4988 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4989 | } finally { |
| 4990 | Binder.restoreCallingIdentity(identity); |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4995 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4996 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4997 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4998 | |
| 4999 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5000 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5001 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5002 | final long identity = Binder.clearCallingIdentity(); |
| 5003 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5004 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5005 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5006 | // 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] | 5007 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5008 | } catch (ImsException e) { |
| 5009 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5010 | } finally { |
| 5011 | Binder.restoreCallingIdentity(identity); |
| 5012 | } |
| 5013 | } |
| 5014 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5015 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5016 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5017 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5018 | * @param subId The subscription to use to check the configuration. |
| 5019 | */ |
| 5020 | @Override |
| 5021 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5022 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5023 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5024 | |
| 5025 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5026 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5027 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5028 | final long identity = Binder.clearCallingIdentity(); |
| 5029 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5030 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5031 | // 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] | 5032 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5033 | } catch (ImsException e) { |
| 5034 | throw new ServiceSpecificException(e.getCode()); |
| 5035 | } finally { |
| 5036 | Binder.restoreCallingIdentity(identity); |
| 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | /** |
| 5041 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5042 | * Requires MODIFY_PHONE_STATE permission. |
| 5043 | * @param subId The subscription to use to check the configuration. |
| 5044 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5045 | * false otherwise |
| 5046 | */ |
| 5047 | @Override |
| 5048 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5050 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5051 | |
| 5052 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5053 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5054 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5055 | final long identity = Binder.clearCallingIdentity(); |
| 5056 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5057 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5058 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5059 | // 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] | 5060 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5061 | } catch (ImsException e) { |
| 5062 | throw new ServiceSpecificException(e.getCode()); |
| 5063 | } finally { |
| 5064 | Binder.restoreCallingIdentity(identity); |
| 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5069 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5070 | * @param subId The subscription to use to check the configuration. |
| 5071 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5072 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5073 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5074 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5075 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5076 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5077 | |
| 5078 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5079 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5080 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5081 | final long identity = Binder.clearCallingIdentity(); |
| 5082 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5083 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5084 | // 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] | 5085 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5086 | } catch (ImsException e) { |
| 5087 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5088 | } finally { |
| 5089 | Binder.restoreCallingIdentity(identity); |
| 5090 | } |
| 5091 | } |
| 5092 | |
| 5093 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5094 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5095 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5096 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5097 | |
| 5098 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5099 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5100 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5101 | final long identity = Binder.clearCallingIdentity(); |
| 5102 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5103 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5104 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5105 | // 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] | 5106 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5107 | } catch (ImsException e) { |
| 5108 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5109 | } finally { |
| 5110 | Binder.restoreCallingIdentity(identity); |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | @Override |
| 5115 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5117 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5118 | |
| 5119 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5120 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5121 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5122 | final long identity = Binder.clearCallingIdentity(); |
| 5123 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5124 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5125 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5126 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5127 | } catch (ImsException e) { |
| 5128 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5129 | } finally { |
| 5130 | Binder.restoreCallingIdentity(identity); |
| 5131 | } |
| 5132 | } |
| 5133 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5134 | /** |
| 5135 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5136 | * @param subId The subscription to use to check the configuration. |
| 5137 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5138 | @Override |
| 5139 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5140 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5141 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5142 | |
| 5143 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5144 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5145 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5146 | final long identity = Binder.clearCallingIdentity(); |
| 5147 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5148 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5149 | // 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] | 5150 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5151 | } catch (ImsException e) { |
| 5152 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5153 | } finally { |
| 5154 | Binder.restoreCallingIdentity(identity); |
| 5155 | } |
| 5156 | } |
| 5157 | |
| 5158 | @Override |
| 5159 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5161 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5162 | |
| 5163 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5164 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5165 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5166 | final long identity = Binder.clearCallingIdentity(); |
| 5167 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5168 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5169 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5170 | // 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] | 5171 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5172 | } catch (ImsException e) { |
| 5173 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
| 5177 | } |
| 5178 | |
| 5179 | @Override |
| 5180 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5181 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5182 | |
| 5183 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5184 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5185 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5186 | final long identity = Binder.clearCallingIdentity(); |
| 5187 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5188 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5189 | // 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] | 5190 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5191 | } catch (ImsException e) { |
| 5192 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5193 | } finally { |
| 5194 | Binder.restoreCallingIdentity(identity); |
| 5195 | } |
| 5196 | } |
| 5197 | |
| 5198 | @Override |
| 5199 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5200 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5201 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5202 | |
| 5203 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5204 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5205 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5206 | final long identity = Binder.clearCallingIdentity(); |
| 5207 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5208 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5209 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5210 | // 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] | 5211 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5212 | } catch (ImsException e) { |
| 5213 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5214 | } finally { |
| 5215 | Binder.restoreCallingIdentity(identity); |
| 5216 | } |
| 5217 | } |
| 5218 | |
| 5219 | @Override |
| 5220 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5222 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5223 | |
| 5224 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5225 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5226 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5227 | final long identity = Binder.clearCallingIdentity(); |
| 5228 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5229 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5230 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5231 | // 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] | 5232 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5233 | } catch (ImsException e) { |
| 5234 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5235 | } finally { |
| 5236 | Binder.restoreCallingIdentity(identity); |
| 5237 | } |
| 5238 | } |
| 5239 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5240 | /** |
| 5241 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5242 | * @param subId The subscription to use to check the configuration. |
| 5243 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5244 | @Override |
| 5245 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5246 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5247 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5248 | |
| 5249 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5250 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5251 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5252 | final long identity = Binder.clearCallingIdentity(); |
| 5253 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5254 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5255 | // 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] | 5256 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5257 | } catch (ImsException e) { |
| 5258 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5259 | } finally { |
| 5260 | Binder.restoreCallingIdentity(identity); |
| 5261 | } |
| 5262 | } |
| 5263 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5264 | @Override |
| 5265 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5266 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5267 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5268 | final long identity = Binder.clearCallingIdentity(); |
| 5269 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5270 | if (!isImsAvailableOnDevice()) { |
| 5271 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5272 | "IMS not available on device."); |
| 5273 | } |
| 5274 | int slotId = getSlotIndexOrException(subId); |
| 5275 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5276 | |
| 5277 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5278 | if (controller != null) { |
| 5279 | ImsManager imsManager = controller.getImsManager(subId); |
| 5280 | if (imsManager != null) { |
| 5281 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5282 | } else { |
| 5283 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5284 | } |
| 5285 | } else { |
| 5286 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5287 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5288 | } catch (ImsException e) { |
| 5289 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5290 | } finally { |
| 5291 | Binder.restoreCallingIdentity(identity); |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | @Override |
| 5296 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5297 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5298 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5299 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5300 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5301 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5302 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5303 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5304 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5305 | if (controller != null) { |
| 5306 | ImsManager imsManager = controller.getImsManager(subId); |
| 5307 | if (imsManager != null) { |
| 5308 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5309 | } else { |
| 5310 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5311 | + " is inactive, ignoring unregister."); |
| 5312 | // If the ImsManager is not valid, just return, since the callback will already |
| 5313 | // have been removed internally. |
| 5314 | } |
| 5315 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5316 | } finally { |
| 5317 | Binder.restoreCallingIdentity(identity); |
| 5318 | } |
| 5319 | } |
| 5320 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5321 | @Override |
| 5322 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5323 | IFeatureProvisioningCallback callback) { |
| 5324 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5325 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5326 | |
| 5327 | final long identity = Binder.clearCallingIdentity(); |
| 5328 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5329 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5330 | } |
| 5331 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5332 | try { |
| 5333 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5334 | if (controller == null) { |
| 5335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5336 | "Device does not support IMS"); |
| 5337 | } |
| 5338 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5339 | } finally { |
| 5340 | Binder.restoreCallingIdentity(identity); |
| 5341 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | @Override |
| 5345 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5346 | IFeatureProvisioningCallback callback) { |
| 5347 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5348 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5349 | |
| 5350 | final long identity = Binder.clearCallingIdentity(); |
| 5351 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5352 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5353 | } |
| 5354 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5355 | try { |
| 5356 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5357 | if (controller == null) { |
| 5358 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5359 | return; |
| 5360 | } |
| 5361 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
| 5364 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5365 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5366 | |
| 5367 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5369 | message); |
| 5370 | } |
| 5371 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5372 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5373 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5374 | boolean isProvisioned) { |
| 5375 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5376 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5377 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5378 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5379 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5380 | final long identity = Binder.clearCallingIdentity(); |
| 5381 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5382 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5383 | if (controller == null) { |
| 5384 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5385 | return; |
| 5386 | } |
| 5387 | controller.setRcsProvisioningStatusForCapability( |
| 5388 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5389 | } finally { |
| 5390 | Binder.restoreCallingIdentity(identity); |
| 5391 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | |
| 5395 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5396 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5397 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5398 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5399 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5400 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5401 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5402 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5403 | final long identity = Binder.clearCallingIdentity(); |
| 5404 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5405 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5406 | if (controller == null) { |
| 5407 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5408 | |
| 5409 | // device does not support IMS, this method will return true always. |
| 5410 | return true; |
| 5411 | } |
| 5412 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5413 | } finally { |
| 5414 | Binder.restoreCallingIdentity(identity); |
| 5415 | } |
| 5416 | } |
| 5417 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5418 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5419 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5420 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5421 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5422 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5423 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5424 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5425 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5426 | final long identity = Binder.clearCallingIdentity(); |
| 5427 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5428 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5429 | if (controller == null) { |
| 5430 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5431 | return; |
| 5432 | } |
| 5433 | controller.setImsProvisioningStatusForCapability( |
| 5434 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | @Override |
| 5441 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5442 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5443 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5444 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5445 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5446 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5447 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5448 | final long identity = Binder.clearCallingIdentity(); |
| 5449 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5450 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5451 | if (controller == null) { |
| 5452 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5453 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5454 | // device does not support IMS, this method will return true always. |
| 5455 | return true; |
| 5456 | } |
| 5457 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5464 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5465 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5466 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5467 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5468 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5469 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5470 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5471 | final long identity = Binder.clearCallingIdentity(); |
| 5472 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5473 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5474 | if (controller == null) { |
| 5475 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5476 | |
| 5477 | // device does not support IMS, this method will return false |
| 5478 | return false; |
| 5479 | } |
| 5480 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5481 | } finally { |
| 5482 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5483 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5487 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5488 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5489 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5490 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5491 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5492 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5493 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5494 | final long identity = Binder.clearCallingIdentity(); |
| 5495 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5496 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5497 | if (controller == null) { |
| 5498 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5499 | |
| 5500 | // device does not support IMS, this method will return false |
| 5501 | return false; |
| 5502 | } |
| 5503 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5504 | } finally { |
| 5505 | Binder.restoreCallingIdentity(identity); |
| 5506 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5509 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5510 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5511 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5512 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5513 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5514 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5515 | mApp, subId, "getImsProvisioningInt"); |
| 5516 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5517 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5518 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5519 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5520 | final long identity = Binder.clearCallingIdentity(); |
| 5521 | try { |
| 5522 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5523 | int slotId = getSlotIndex(subId); |
| 5524 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5525 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5526 | + subId + "' for key:" + key); |
| 5527 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5528 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5529 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5530 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5531 | if (controller == null) { |
| 5532 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5533 | |
| 5534 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5535 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5536 | } |
| 5537 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5538 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5539 | return retVal; |
| 5540 | } |
| 5541 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5542 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5543 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5544 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5545 | + subId + "' for key:" + key); |
| 5546 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5547 | } finally { |
| 5548 | Binder.restoreCallingIdentity(identity); |
| 5549 | } |
| 5550 | } |
| 5551 | |
| 5552 | @Override |
| 5553 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5554 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5555 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5556 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5557 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5558 | mApp, subId, "getImsProvisioningString"); |
| 5559 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5560 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5561 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5562 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5563 | final long identity = Binder.clearCallingIdentity(); |
| 5564 | try { |
| 5565 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5566 | int slotId = getSlotIndex(subId); |
| 5567 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5568 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5569 | + subId + "' for key:" + key); |
| 5570 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5571 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5572 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5573 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5574 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5575 | + subId + "' for key:" + key); |
| 5576 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5577 | } finally { |
| 5578 | Binder.restoreCallingIdentity(identity); |
| 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | @Override |
| 5583 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5584 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5585 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5586 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5588 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5589 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5590 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5591 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5592 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5593 | final long identity = Binder.clearCallingIdentity(); |
| 5594 | try { |
| 5595 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5596 | int slotId = getSlotIndex(subId); |
| 5597 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5598 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5599 | + subId + "' for key:" + key); |
| 5600 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5601 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5602 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5603 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5604 | if (controller == null) { |
| 5605 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5606 | |
| 5607 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5608 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5609 | } |
| 5610 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5611 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5612 | return retVal; |
| 5613 | } |
| 5614 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5615 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5616 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5617 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5618 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5619 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5620 | } finally { |
| 5621 | Binder.restoreCallingIdentity(identity); |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | @Override |
| 5626 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5627 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5628 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5629 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5631 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5632 | |
| 5633 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5634 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5635 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5636 | final long identity = Binder.clearCallingIdentity(); |
| 5637 | try { |
| 5638 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5639 | int slotId = getSlotIndex(subId); |
| 5640 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5641 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5642 | + subId + "' for key:" + key); |
| 5643 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5644 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5645 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5646 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5647 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5648 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5649 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5650 | } finally { |
| 5651 | Binder.restoreCallingIdentity(identity); |
| 5652 | } |
| 5653 | } |
| 5654 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5655 | /** |
| 5656 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5657 | * for the given slot ID or no ImsResolver instance has been created. |
| 5658 | * @param slotId The slot ID that the IMS service is created for. |
| 5659 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5660 | */ |
| 5661 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5662 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5663 | ImsFeature.FEATURE_MMTEL)) { |
| 5664 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5665 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5666 | } |
| 5667 | } |
| 5668 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5669 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5670 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5671 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5672 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5673 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5674 | } |
| 5675 | return slotId; |
| 5676 | } |
| 5677 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5678 | private int getSlotIndex(int subId) { |
| 5679 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5680 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5681 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5682 | } |
| 5683 | return slotId; |
| 5684 | } |
| 5685 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5686 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5687 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5688 | */ |
| 5689 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5690 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5691 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5692 | try { |
| 5693 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5694 | } catch (SecurityException se) { |
| 5695 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5696 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5697 | + Binder.getCallingUid()); |
| 5698 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5699 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5700 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5701 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5702 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5703 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5704 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5705 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5706 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5707 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5708 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5709 | enforceTelephonyFeatureWithException(callingPackage, |
| 5710 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5711 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5712 | final long identity = Binder.clearCallingIdentity(); |
| 5713 | try { |
| 5714 | final Phone phone = getPhone(subId); |
| 5715 | if (phone != null) { |
| 5716 | return phone.getServiceState().getDataNetworkType(); |
| 5717 | } else { |
| 5718 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5719 | } |
| 5720 | } finally { |
| 5721 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5722 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | /** |
| 5726 | * Returns the data network type |
| 5727 | */ |
| 5728 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5729 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5730 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5731 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | /** |
| 5735 | * Returns the data network type for a subId |
| 5736 | */ |
| 5737 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5738 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5739 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5740 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5741 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5742 | mApp, functionName)) { |
| 5743 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5744 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5745 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5746 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5749 | enforceTelephonyFeatureWithException(callingPackage, |
| 5750 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5751 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5752 | final long identity = Binder.clearCallingIdentity(); |
| 5753 | try { |
| 5754 | final Phone phone = getPhone(subId); |
| 5755 | if (phone != null) { |
| 5756 | return phone.getServiceState().getDataNetworkType(); |
| 5757 | } else { |
| 5758 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5759 | } |
| 5760 | } finally { |
| 5761 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5762 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5766 | * Returns the Voice network type for a subId |
| 5767 | */ |
| 5768 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5769 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5770 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5771 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5772 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5773 | mApp, functionName)) { |
| 5774 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5775 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5776 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5777 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5778 | } |
| 5779 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5780 | enforceTelephonyFeatureWithException(callingPackage, |
| 5781 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5782 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5783 | final long identity = Binder.clearCallingIdentity(); |
| 5784 | try { |
| 5785 | final Phone phone = getPhone(subId); |
| 5786 | if (phone != null) { |
| 5787 | return phone.getServiceState().getVoiceNetworkType(); |
| 5788 | } else { |
| 5789 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5790 | } |
| 5791 | } finally { |
| 5792 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5793 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5794 | } |
| 5795 | |
| 5796 | /** |
| 5797 | * @return true if a ICC card is present |
| 5798 | */ |
| 5799 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5800 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5801 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5802 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5806 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5807 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5808 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5809 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5810 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5811 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5812 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5813 | final long identity = Binder.clearCallingIdentity(); |
| 5814 | try { |
| 5815 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5816 | if (phone != null) { |
| 5817 | return phone.getIccCard().hasIccCard(); |
| 5818 | } else { |
| 5819 | return false; |
| 5820 | } |
| 5821 | } finally { |
| 5822 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5823 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | /** |
| 5827 | * Return if the current radio is LTE on CDMA. This |
| 5828 | * is a tri-state return value as for a period of time |
| 5829 | * the mode may be unknown. |
| 5830 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5831 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5832 | * @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] | 5833 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5834 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5835 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5836 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5837 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5838 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5839 | } |
| 5840 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5841 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5842 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5843 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5844 | try { |
| 5845 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5846 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5847 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5848 | } |
| 5849 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5850 | enforceTelephonyFeatureWithException(callingPackage, |
| 5851 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5852 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5853 | final long identity = Binder.clearCallingIdentity(); |
| 5854 | try { |
| 5855 | final Phone phone = getPhone(subId); |
| 5856 | if (phone == null) { |
| 5857 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5858 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5859 | return TelephonyProperties.lte_on_cdma_device() |
| 5860 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | } |
| 5862 | } finally { |
| 5863 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5864 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5865 | } |
| 5866 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5867 | /** |
| 5868 | * {@hide} |
| 5869 | * Returns Default subId, 0 in the case of single standby. |
| 5870 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5871 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5872 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5873 | } |
| 5874 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5875 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5876 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5877 | } |
| 5878 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5879 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5880 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5881 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5882 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5883 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5884 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5885 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5888 | /** |
| 5889 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5890 | */ |
| 5891 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | final long identity = Binder.clearCallingIdentity(); |
| 5893 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5894 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5896 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
| 5899 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5900 | } |
| 5901 | |
| 5902 | /** |
| 5903 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5904 | */ |
| 5905 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5906 | final long identity = Binder.clearCallingIdentity(); |
| 5907 | try { |
| 5908 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5909 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5910 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5911 | } finally { |
| 5912 | Binder.restoreCallingIdentity(identity); |
| 5913 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5914 | } |
| 5915 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5916 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5917 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5918 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5919 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5920 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5921 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5922 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5923 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5924 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5925 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5926 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5927 | } |
| 5928 | return PhoneFactory.getPhone(phoneId); |
| 5929 | } |
| 5930 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5931 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5932 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5933 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5934 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5935 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5936 | /*message=*/ "iccOpenLogicalChannel"); |
| 5937 | |
| 5938 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5939 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5940 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5941 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5942 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5943 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5944 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5945 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5946 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5947 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5948 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5949 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5950 | Phone phone; |
| 5951 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5953 | mApp, request.subId, message); |
| 5954 | phone = getPhoneFromSubId(request.subId); |
| 5955 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5956 | enforceModifyPermission(); |
| 5957 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5958 | } else { |
| 5959 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5960 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5961 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5965 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5966 | final long identity = Binder.clearCallingIdentity(); |
| 5967 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5968 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5970 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5971 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5972 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5973 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | loge("The calling package is not allowed to access ISD-R."); |
| 5975 | throw new SecurityException( |
| 5976 | "The calling package is not allowed to access ISD-R."); |
| 5977 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5978 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5979 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5980 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5981 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5982 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5983 | return response; |
| 5984 | } finally { |
| 5985 | Binder.restoreCallingIdentity(identity); |
| 5986 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5990 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5991 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5992 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 5993 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5994 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5995 | /*message=*/"iccCloseLogicalChannel"); |
| 5996 | |
| 5997 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5998 | |
| 5999 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6000 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6001 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6002 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6003 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6004 | // before this feature is enabled, this API should only return false if |
| 6005 | // the operation fails instead of throwing runtime exception for |
| 6006 | // backward-compatibility. |
| 6007 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6008 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | final long identity = Binder.clearCallingIdentity(); |
| 6010 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6011 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6012 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6014 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6015 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6016 | Boolean success = false; |
| 6017 | if (result instanceof RuntimeException) { |
| 6018 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6019 | if (shouldThrowExceptionOnFailure) { |
| 6020 | throw (RuntimeException) result; |
| 6021 | } else { |
| 6022 | return false; |
| 6023 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6024 | } else if (result instanceof Boolean) { |
| 6025 | success = (Boolean) result; |
| 6026 | } else { |
| 6027 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6028 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6029 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | return success; |
| 6031 | } finally { |
| 6032 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6033 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6037 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6038 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6040 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6041 | |
| 6042 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6043 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6044 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6045 | if (DBG) { |
| 6046 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6047 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6048 | + p3 + " data=" + data); |
| 6049 | } |
| 6050 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6051 | command, p1, p2, p3, data); |
| 6052 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6053 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6054 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6055 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6056 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6057 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6058 | |
| 6059 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6060 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6061 | "iccTransmitApduLogicalChannelBySlot"); |
| 6062 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6063 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6064 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6065 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6066 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6067 | } |
| 6068 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6069 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6070 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6071 | } |
| 6072 | |
| 6073 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6074 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6075 | final long identity = Binder.clearCallingIdentity(); |
| 6076 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6077 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | return ""; |
| 6079 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6082 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6083 | null /* workSource */); |
| 6084 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6086 | // Append the returned status code to the end of the response payload. |
| 6087 | String s = Integer.toHexString( |
| 6088 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6089 | if (response.payload != null) { |
| 6090 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6091 | } |
| 6092 | return s; |
| 6093 | } finally { |
| 6094 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6095 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6096 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6097 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6098 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6099 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6100 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6102 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6103 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6104 | |
| 6105 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6106 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6107 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6108 | if (DBG) { |
| 6109 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6110 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6111 | } |
| 6112 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6113 | cla, command, p1, p2, p3, data); |
| 6114 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6115 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6116 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6117 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6118 | 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] | 6119 | enforceModifyPermission(); |
| 6120 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6121 | |
| 6122 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6123 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6124 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6125 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6126 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6127 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6128 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6132 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6133 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6137 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6138 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6139 | final long identity = Binder.clearCallingIdentity(); |
| 6140 | try { |
| 6141 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6142 | && TextUtils.equals(ISDR_AID, data)) { |
| 6143 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6144 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6145 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6146 | if (bestComponent == null |
| 6147 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6148 | loge("The calling package is not allowed to select ISD-R."); |
| 6149 | throw new SecurityException( |
| 6150 | "The calling package is not allowed to select ISD-R."); |
| 6151 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6152 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6153 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6154 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6155 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6156 | null /* workSource */); |
| 6157 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6158 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6159 | // Append the returned status code to the end of the response payload. |
| 6160 | String s = Integer.toHexString( |
| 6161 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6162 | if (response.payload != null) { |
| 6163 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6164 | } |
| 6165 | return s; |
| 6166 | } finally { |
| 6167 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6168 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6172 | 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] | 6173 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6174 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6175 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6176 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6177 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6178 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6179 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6180 | final long identity = Binder.clearCallingIdentity(); |
| 6181 | try { |
| 6182 | if (DBG) { |
| 6183 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6184 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6185 | } |
| 6186 | |
| 6187 | IccIoResult response = |
| 6188 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6189 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6190 | subId); |
| 6191 | |
| 6192 | if (DBG) { |
| 6193 | log("Exchange SIM_IO [R]" + response); |
| 6194 | } |
| 6195 | |
| 6196 | byte[] result = null; |
| 6197 | int length = 2; |
| 6198 | if (response.payload != null) { |
| 6199 | length = 2 + response.payload.length; |
| 6200 | result = new byte[length]; |
| 6201 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6202 | } else { |
| 6203 | result = new byte[length]; |
| 6204 | } |
| 6205 | |
| 6206 | result[length - 1] = (byte) response.sw2; |
| 6207 | result[length - 2] = (byte) response.sw1; |
| 6208 | return result; |
| 6209 | } finally { |
| 6210 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6211 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6212 | } |
| 6213 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6214 | /** |
| 6215 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6216 | * on a particular subscription |
| 6217 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6218 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6219 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6220 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6221 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6222 | return null; |
| 6223 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6225 | enforceTelephonyFeatureWithException(callingPackage, |
| 6226 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6228 | final long identity = Binder.clearCallingIdentity(); |
| 6229 | try { |
| 6230 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6231 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6232 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6233 | return null; |
| 6234 | } |
| 6235 | Object response = sendRequest( |
| 6236 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6237 | if (response instanceof String[]) { |
| 6238 | return (String[]) response; |
| 6239 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6240 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6242 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6243 | } finally { |
| 6244 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6245 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6246 | } |
| 6247 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6248 | /** |
| 6249 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6250 | * subscription. |
| 6251 | * |
| 6252 | * @param subId the id of the subscription. |
| 6253 | * @param appType the uicc app type, must be USIM or SIM. |
| 6254 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6255 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6256 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6257 | * @return number of fplmns that is successfully written to the SIM. |
| 6258 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6259 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6260 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6261 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6262 | mApp, subId, "setForbiddenPlmns"); |
| 6263 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6264 | enforceTelephonyFeatureWithException(callingPackage, |
| 6265 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6266 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6267 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6268 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6269 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6270 | } |
| 6271 | if (fplmns == null) { |
| 6272 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6273 | } |
| 6274 | for (String fplmn : fplmns) { |
| 6275 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6276 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6277 | } |
| 6278 | } |
| 6279 | final long identity = Binder.clearCallingIdentity(); |
| 6280 | try { |
| 6281 | Object response = sendRequest( |
| 6282 | CMD_SET_FORBIDDEN_PLMNS, |
| 6283 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6284 | subId); |
| 6285 | return (int) response; |
| 6286 | } finally { |
| 6287 | Binder.restoreCallingIdentity(identity); |
| 6288 | } |
| 6289 | } |
| 6290 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6291 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6292 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6294 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6295 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6296 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6297 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6298 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | final long identity = Binder.clearCallingIdentity(); |
| 6300 | try { |
| 6301 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6302 | if (response.payload == null) { |
| 6303 | return ""; |
| 6304 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6305 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | // Append the returned status code to the end of the response payload. |
| 6307 | String s = Integer.toHexString( |
| 6308 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6309 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6310 | return s; |
| 6311 | } finally { |
| 6312 | Binder.restoreCallingIdentity(identity); |
| 6313 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6314 | } |
| 6315 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6316 | /** |
| 6317 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6318 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6319 | * |
| 6320 | * @param itemID the ID of the item to read |
| 6321 | * @return the NV item as a String, or null on error. |
| 6322 | */ |
| 6323 | @Override |
| 6324 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6325 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6327 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | |
| 6329 | final long identity = Binder.clearCallingIdentity(); |
| 6330 | try { |
| 6331 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6332 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6333 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6334 | return value; |
| 6335 | } finally { |
| 6336 | Binder.restoreCallingIdentity(identity); |
| 6337 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6338 | } |
| 6339 | |
| 6340 | /** |
| 6341 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6342 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6343 | * |
| 6344 | * @param itemID the ID of the item to read |
| 6345 | * @param itemValue the value to write, as a String |
| 6346 | * @return true on success; false on any failure |
| 6347 | */ |
| 6348 | @Override |
| 6349 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6350 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6352 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | |
| 6354 | final long identity = Binder.clearCallingIdentity(); |
| 6355 | try { |
| 6356 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6357 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6358 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6360 | return success; |
| 6361 | } finally { |
| 6362 | Binder.restoreCallingIdentity(identity); |
| 6363 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | /** |
| 6367 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6368 | * Used for device configuration by some CDMA operators. |
| 6369 | * |
| 6370 | * @param preferredRoamingList byte array containing the new PRL |
| 6371 | * @return true on success; false on any failure |
| 6372 | */ |
| 6373 | @Override |
| 6374 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6376 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6377 | |
| 6378 | final long identity = Binder.clearCallingIdentity(); |
| 6379 | try { |
| 6380 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6381 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6382 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6383 | return success; |
| 6384 | } finally { |
| 6385 | Binder.restoreCallingIdentity(identity); |
| 6386 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6390 | * 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] | 6391 | * Used for device configuration by some CDMA operators. |
| 6392 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6393 | * @param slotIndex - device slot. |
| 6394 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6395 | * @return true on success; false on any failure |
| 6396 | */ |
| 6397 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6398 | public boolean resetModemConfig(int slotIndex) { |
| 6399 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6400 | if (phone != null) { |
| 6401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6402 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6403 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6404 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6405 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6406 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6407 | final long identity = Binder.clearCallingIdentity(); |
| 6408 | try { |
| 6409 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6410 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6411 | return success; |
| 6412 | } finally { |
| 6413 | Binder.restoreCallingIdentity(identity); |
| 6414 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6416 | return false; |
| 6417 | } |
| 6418 | |
| 6419 | /** |
| 6420 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6421 | * |
| 6422 | * @param slotIndex - device slot. |
| 6423 | * |
| 6424 | * @return true on success; false on any failure |
| 6425 | */ |
| 6426 | @Override |
| 6427 | public boolean rebootModem(int slotIndex) { |
| 6428 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6429 | if (phone != null) { |
| 6430 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6431 | mApp, phone.getSubId(), "rebootModem"); |
| 6432 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6433 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6434 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6435 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6436 | final long identity = Binder.clearCallingIdentity(); |
| 6437 | try { |
| 6438 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6439 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6440 | return success; |
| 6441 | } finally { |
| 6442 | Binder.restoreCallingIdentity(identity); |
| 6443 | } |
| 6444 | } |
| 6445 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6446 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6447 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6448 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6449 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6450 | * {@link #disableIms(int)}. |
| 6451 | * @param slotIndex device slot. |
| 6452 | */ |
| 6453 | public void resetIms(int slotIndex) { |
| 6454 | enforceModifyPermission(); |
| 6455 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6456 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6457 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6458 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
| 6461 | if (mImsResolver == null) { |
| 6462 | // may happen if the does not support IMS. |
| 6463 | return; |
| 6464 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6465 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6466 | } finally { |
| 6467 | Binder.restoreCallingIdentity(identity); |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6472 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6473 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6474 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6475 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6476 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6477 | |
| 6478 | final long identity = Binder.clearCallingIdentity(); |
| 6479 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6480 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6481 | // may happen if the device does not support IMS. |
| 6482 | return; |
| 6483 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6484 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6485 | } finally { |
| 6486 | Binder.restoreCallingIdentity(identity); |
| 6487 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6491 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6492 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6493 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6494 | public void disableIms(int slotId) { |
| 6495 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6496 | |
| 6497 | final long identity = Binder.clearCallingIdentity(); |
| 6498 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6499 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6500 | // may happen if the device does not support IMS. |
| 6501 | return; |
| 6502 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6503 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6504 | } finally { |
| 6505 | Binder.restoreCallingIdentity(identity); |
| 6506 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6507 | } |
| 6508 | |
| 6509 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6510 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6511 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6512 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6513 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6514 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6515 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6516 | |
| 6517 | final long identity = Binder.clearCallingIdentity(); |
| 6518 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6519 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6520 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6521 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6522 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6523 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6524 | } finally { |
| 6525 | Binder.restoreCallingIdentity(identity); |
| 6526 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6527 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6528 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6529 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6530 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6531 | @Override |
| 6532 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6533 | enforceModifyPermission(); |
| 6534 | |
| 6535 | final long identity = Binder.clearCallingIdentity(); |
| 6536 | try { |
| 6537 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6538 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6539 | } finally { |
| 6540 | Binder.restoreCallingIdentity(identity); |
| 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6545 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6546 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6547 | */ |
| 6548 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6549 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6550 | |
| 6551 | final long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6553 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6554 | // may happen if the device does not support IMS. |
| 6555 | return null; |
| 6556 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6557 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6558 | } finally { |
| 6559 | Binder.restoreCallingIdentity(identity); |
| 6560 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6561 | } |
| 6562 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6563 | /** |
| 6564 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6565 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6566 | */ |
| 6567 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6568 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6569 | |
| 6570 | final long identity = Binder.clearCallingIdentity(); |
| 6571 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6572 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6573 | // may happen if the device does not support IMS. |
| 6574 | return null; |
| 6575 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6576 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | } finally { |
| 6578 | Binder.restoreCallingIdentity(identity); |
| 6579 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6580 | } |
| 6581 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6582 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6583 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6584 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6585 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6586 | * @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] | 6587 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6588 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6589 | * @param packageName The name of the package that the current configuration will be replaced |
| 6590 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6591 | * @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] | 6592 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6593 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6594 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6595 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6597 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6598 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6599 | final long identity = Binder.clearCallingIdentity(); |
| 6600 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6601 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6602 | // may happen if the device does not support IMS. |
| 6603 | return false; |
| 6604 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6605 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6606 | for (int featureType : featureTypes) { |
| 6607 | featureConfig.put(featureType, packageName); |
| 6608 | } |
| 6609 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6610 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6611 | } finally { |
| 6612 | Binder.restoreCallingIdentity(identity); |
| 6613 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6614 | } |
| 6615 | |
| 6616 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6617 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6618 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6619 | * |
| 6620 | * This should only be used for testing. |
| 6621 | * |
| 6622 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6623 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6624 | */ |
| 6625 | @Override |
| 6626 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6627 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6628 | "clearCarrierImsServiceOverride"); |
| 6629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6630 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6631 | |
| 6632 | final long identity = Binder.clearCallingIdentity(); |
| 6633 | try { |
| 6634 | if (mImsResolver == null) { |
| 6635 | // may happen if the device does not support IMS. |
| 6636 | return false; |
| 6637 | } |
| 6638 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6639 | } finally { |
| 6640 | Binder.restoreCallingIdentity(identity); |
| 6641 | } |
| 6642 | } |
| 6643 | |
| 6644 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6645 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6646 | * |
| 6647 | * @param slotId The slot that the ImsService is associated with. |
| 6648 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6649 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6650 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6651 | * @return the package name of the ImsService configuration. |
| 6652 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6653 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6654 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6655 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6656 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6657 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6658 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | final long identity = Binder.clearCallingIdentity(); |
| 6660 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6661 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6662 | // may happen if the device does not support IMS. |
| 6663 | return ""; |
| 6664 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6665 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6666 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6667 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6668 | } finally { |
| 6669 | Binder.restoreCallingIdentity(identity); |
| 6670 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6671 | } |
| 6672 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6673 | /** |
| 6674 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6675 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6676 | * @param callback A callback with an integer containing the |
| 6677 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6678 | */ |
| 6679 | @Override |
| 6680 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6681 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6682 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6683 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6684 | "IMS not available on device."); |
| 6685 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6686 | final long token = Binder.clearCallingIdentity(); |
| 6687 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6688 | int slotId = getSlotIndex(subId); |
| 6689 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6690 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6691 | + subId + "'"); |
| 6692 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6693 | } |
| 6694 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6695 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6696 | try { |
| 6697 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6698 | } catch (RemoteException e) { |
| 6699 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6700 | + "Ignore"); |
| 6701 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6702 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6703 | } catch (ImsException e) { |
| 6704 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6705 | } finally { |
| 6706 | Binder.restoreCallingIdentity(token); |
| 6707 | } |
| 6708 | } |
| 6709 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6710 | /** |
| 6711 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6712 | */ |
| 6713 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6714 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | |
| 6716 | final long identity = Binder.clearCallingIdentity(); |
| 6717 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6718 | // NOTE: Before S, this method only set the default phone. |
| 6719 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6720 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6721 | phone.setImsRegistrationState(registered); |
| 6722 | } |
| 6723 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | } finally { |
| 6725 | Binder.restoreCallingIdentity(identity); |
| 6726 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6730 | * Set the network selection mode to automatic. |
| 6731 | * |
| 6732 | */ |
| 6733 | @Override |
| 6734 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6736 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6737 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6738 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6739 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6740 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | final long identity = Binder.clearCallingIdentity(); |
| 6742 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6743 | if (!isActiveSubscription(subId)) { |
| 6744 | return; |
| 6745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6747 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6748 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6749 | } finally { |
| 6750 | Binder.restoreCallingIdentity(identity); |
| 6751 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6752 | } |
| 6753 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6754 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6755 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6756 | * |
| 6757 | * @param subId the id of the subscription. |
| 6758 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6759 | * the operator to attach to. |
| 6760 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6761 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6762 | * normal network selection next time. |
| 6763 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6764 | */ |
| 6765 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6766 | public boolean setNetworkSelectionModeManual( |
| 6767 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6768 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6769 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6770 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6771 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6772 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6773 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6774 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6775 | if (!isActiveSubscription(subId)) { |
| 6776 | return false; |
| 6777 | } |
| 6778 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6780 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6781 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6782 | if (DBG) { |
| 6783 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6784 | + " operator: " + operatorInfo); |
| 6785 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6786 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6787 | } finally { |
| 6788 | Binder.restoreCallingIdentity(identity); |
| 6789 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6790 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6791 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6792 | * Get the manual network selection |
| 6793 | * |
| 6794 | * @param subId the id of the subscription. |
| 6795 | * |
| 6796 | * @return the previously saved user selected PLMN |
| 6797 | */ |
| 6798 | @Override |
| 6799 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6800 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6801 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6802 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6803 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6804 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6805 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6806 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6807 | final long identity = Binder.clearCallingIdentity(); |
| 6808 | try { |
| 6809 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6810 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | final Phone phone = getPhone(subId); |
| 6814 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6815 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6816 | } |
| 6817 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6818 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6819 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6820 | } finally { |
| 6821 | Binder.restoreCallingIdentity(identity); |
| 6822 | } |
| 6823 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6824 | |
| 6825 | /** |
| 6826 | * Scans for available networks. |
| 6827 | */ |
| 6828 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6829 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6830 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6831 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6832 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6833 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6834 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6835 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6836 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6837 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6838 | .setCallingPid(Binder.getCallingPid()) |
| 6839 | .setCallingUid(Binder.getCallingUid()) |
| 6840 | .setMethod("getCellNetworkScanResults") |
| 6841 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6842 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6843 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6844 | .build()); |
| 6845 | switch (locationResult) { |
| 6846 | case DENIED_HARD: |
| 6847 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6848 | case DENIED_SOFT: |
| 6849 | return null; |
| 6850 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6851 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6852 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6853 | try { |
| 6854 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6855 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6856 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6857 | } finally { |
| 6858 | Binder.restoreCallingIdentity(identity); |
| 6859 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6860 | } |
| 6861 | |
| 6862 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6863 | * Get the call forwarding info, given the call forwarding reason. |
| 6864 | */ |
| 6865 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6866 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6867 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6868 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6869 | |
| 6870 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6871 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6872 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6873 | long identity = Binder.clearCallingIdentity(); |
| 6874 | try { |
| 6875 | if (DBG) { |
| 6876 | log("getCallForwarding: subId " + subId |
| 6877 | + " callForwardingReason" + callForwardingReason); |
| 6878 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6879 | |
| 6880 | Phone phone = getPhone(subId); |
| 6881 | if (phone == null) { |
| 6882 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6883 | callback.onError( |
| 6884 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6885 | } catch (RemoteException e) { |
| 6886 | // ignore |
| 6887 | } |
| 6888 | return; |
| 6889 | } |
| 6890 | |
| 6891 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6892 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6893 | @Override |
| 6894 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6895 | try { |
| 6896 | callback.onCallForwardingInfoAvailable(info); |
| 6897 | } catch (RemoteException e) { |
| 6898 | // ignore |
| 6899 | } |
| 6900 | } |
| 6901 | |
| 6902 | @Override |
| 6903 | public void onError(int error) { |
| 6904 | try { |
| 6905 | callback.onError(error); |
| 6906 | } catch (RemoteException e) { |
| 6907 | // ignore |
| 6908 | } |
| 6909 | } |
| 6910 | }); |
| 6911 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6912 | } finally { |
| 6913 | Binder.restoreCallingIdentity(identity); |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | /** |
| 6918 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6919 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6920 | */ |
| 6921 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6922 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6923 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6924 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6925 | |
| 6926 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6927 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6928 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6929 | long identity = Binder.clearCallingIdentity(); |
| 6930 | try { |
| 6931 | if (DBG) { |
| 6932 | log("setCallForwarding: subId " + subId |
| 6933 | + " callForwardingInfo" + callForwardingInfo); |
| 6934 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6935 | |
| 6936 | Phone phone = getPhone(subId); |
| 6937 | if (phone == null) { |
| 6938 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6939 | callback.accept( |
| 6940 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6941 | } catch (RemoteException e) { |
| 6942 | // ignore |
| 6943 | } |
| 6944 | return; |
| 6945 | } |
| 6946 | |
| 6947 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6948 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6949 | |
| 6950 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6951 | } finally { |
| 6952 | Binder.restoreCallingIdentity(identity); |
| 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6957 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6958 | */ |
| 6959 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6960 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6961 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6962 | |
| 6963 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6964 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 6965 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6966 | long identity = Binder.clearCallingIdentity(); |
| 6967 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6968 | Phone phone = getPhone(subId); |
| 6969 | if (phone == null) { |
| 6970 | try { |
| 6971 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6972 | } catch (RemoteException e) { |
| 6973 | // ignore |
| 6974 | } |
| 6975 | return; |
| 6976 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6977 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6978 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6979 | boolean requireUssd = c.getBoolean( |
| 6980 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6981 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6982 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6983 | if (requireUssd) { |
| 6984 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6985 | getSubscriptionCarrierId(subId)); |
| 6986 | String newUssdCommand = ""; |
| 6987 | try { |
| 6988 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6989 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6990 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6991 | } catch (NullPointerException e) { |
| 6992 | loge("Failed to generate USSD number" + e); |
| 6993 | } |
| 6994 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6995 | mMainThreadHandler, callback, carrierXmlParser, |
| 6996 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6997 | final String ussdCommand = newUssdCommand; |
| 6998 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6999 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7000 | }); |
| 7001 | } else { |
| 7002 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7003 | callback::accept); |
| 7004 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7005 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7006 | } finally { |
| 7007 | Binder.restoreCallingIdentity(identity); |
| 7008 | } |
| 7009 | } |
| 7010 | |
| 7011 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7012 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7013 | */ |
| 7014 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7015 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7016 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7017 | |
| 7018 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7019 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7020 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7021 | long identity = Binder.clearCallingIdentity(); |
| 7022 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7023 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7024 | |
| 7025 | Phone phone = getPhone(subId); |
| 7026 | if (phone == null) { |
| 7027 | try { |
| 7028 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7029 | } catch (RemoteException e) { |
| 7030 | // ignore |
| 7031 | } |
| 7032 | return; |
| 7033 | } |
| 7034 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7035 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7036 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7037 | boolean requireUssd = c.getBoolean( |
| 7038 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7039 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7040 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7041 | if (requireUssd) { |
| 7042 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7043 | getSubscriptionCarrierId(subId)); |
| 7044 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7045 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7046 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7047 | String newUssdCommand = ""; |
| 7048 | try { |
| 7049 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7050 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7051 | .makeCommand(ssAction, null); |
| 7052 | } catch (NullPointerException e) { |
| 7053 | loge("Failed to generate USSD number" + e); |
| 7054 | } |
| 7055 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7056 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7057 | final String ussdCommand = newUssdCommand; |
| 7058 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7059 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7060 | }); |
| 7061 | } else { |
| 7062 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7063 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7064 | |
| 7065 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7066 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7067 | } finally { |
| 7068 | Binder.restoreCallingIdentity(identity); |
| 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7073 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7074 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7075 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7076 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7077 | * location related information which will be sent if the caller already possess |
| 7078 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7079 | * @param request contains the radio access networks with bands/channels to scan |
| 7080 | * @param messenger callback messenger for scan results or errors |
| 7081 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7082 | * @return the id of the requested scan which can be used to stop the scan. |
| 7083 | */ |
| 7084 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7085 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7086 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7087 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7089 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7090 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7091 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7092 | if (!renounceFineLocationAccess) { |
| 7093 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7094 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7095 | .setCallingPackage(callingPackage) |
| 7096 | .setCallingFeatureId(callingFeatureId) |
| 7097 | .setCallingPid(Binder.getCallingPid()) |
| 7098 | .setCallingUid(Binder.getCallingUid()) |
| 7099 | .setMethod("requestNetworkScan") |
| 7100 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7101 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7102 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7103 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7104 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7105 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7106 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7107 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7108 | if (e != null) { |
| 7109 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7110 | throw e; |
| 7111 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7112 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7113 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7114 | } |
| 7115 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7116 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7117 | |
| 7118 | enforceTelephonyFeatureWithException(callingPackage, |
| 7119 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7120 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7121 | int callingUid = Binder.getCallingUid(); |
| 7122 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7123 | final long identity = Binder.clearCallingIdentity(); |
| 7124 | try { |
| 7125 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7126 | renounceFineLocationAccess, request, messenger, binder, |
| 7127 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7128 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7129 | } finally { |
| 7130 | Binder.restoreCallingIdentity(identity); |
| 7131 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7132 | } |
| 7133 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7134 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7135 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7136 | boolean hasCarrierPriv; |
| 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
| 7139 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7140 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7141 | } finally { |
| 7142 | Binder.restoreCallingIdentity(identity); |
| 7143 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7144 | boolean hasNetworkScanPermission = |
| 7145 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7146 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7147 | |
| 7148 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7149 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7150 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7151 | } |
| 7152 | |
| 7153 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7154 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7155 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7156 | return new SecurityException("Specific channels must not be" |
| 7157 | + " scanned without location access."); |
| 7158 | } |
| 7159 | } |
| 7160 | } |
| 7161 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7162 | return null; |
| 7163 | } |
| 7164 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7165 | /** |
| 7166 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7167 | * |
| 7168 | * @param subId id of the subscription |
| 7169 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7170 | */ |
| 7171 | @Override |
| 7172 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7174 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7175 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7176 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7177 | final long identity = Binder.clearCallingIdentity(); |
| 7178 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7179 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | } finally { |
| 7181 | Binder.restoreCallingIdentity(identity); |
| 7182 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7186 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7187 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7188 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7189 | */ |
| 7190 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7191 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7192 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7193 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7194 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7195 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7196 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7197 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7198 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7201 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7202 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7203 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7204 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7205 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7206 | } finally { |
| 7207 | Binder.restoreCallingIdentity(identity); |
| 7208 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7212 | * Get the allowed network types for certain reason. |
| 7213 | * |
| 7214 | * @param subId the id of the subscription. |
| 7215 | * @param reason the reason the allowed network type change is taking place |
| 7216 | * @return the allowed network types. |
| 7217 | */ |
| 7218 | @Override |
| 7219 | public long getAllowedNetworkTypesForReason(int subId, |
| 7220 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7221 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7222 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7223 | |
| 7224 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7225 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7226 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7227 | final long identity = Binder.clearCallingIdentity(); |
| 7228 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7229 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7230 | } finally { |
| 7231 | Binder.restoreCallingIdentity(identity); |
| 7232 | } |
| 7233 | } |
| 7234 | |
| 7235 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7236 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7237 | * @param subId subscription id of the sim card |
| 7238 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7239 | * This can be passed following states |
| 7240 | * <ol> |
| 7241 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7242 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7243 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7244 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7245 | * </ol> |
| 7246 | * @return operation result. |
| 7247 | */ |
| 7248 | @Override |
| 7249 | public int setNrDualConnectivityState(int subId, |
| 7250 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7252 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7253 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7254 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7255 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7256 | } |
| 7257 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7258 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7259 | final long identity = Binder.clearCallingIdentity(); |
| 7260 | try { |
| 7261 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7262 | nrDualConnectivityState, subId, |
| 7263 | workSource); |
| 7264 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7265 | return result; |
| 7266 | } finally { |
| 7267 | Binder.restoreCallingIdentity(identity); |
| 7268 | } |
| 7269 | } |
| 7270 | |
| 7271 | /** |
| 7272 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7273 | * @return true if dual connectivity is enabled else false |
| 7274 | */ |
| 7275 | @Override |
| 7276 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7277 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7278 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7279 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7280 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7281 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7282 | return false; |
| 7283 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7284 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7285 | final long identity = Binder.clearCallingIdentity(); |
| 7286 | try { |
| 7287 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7288 | null, subId, workSource); |
| 7289 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7290 | return isEnabled; |
| 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
| 7293 | } |
| 7294 | } |
| 7295 | |
| 7296 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7297 | * Set the allowed network types of the device and |
| 7298 | * provide the reason triggering the allowed network change. |
| 7299 | * |
| 7300 | * @param subId the id of the subscription. |
| 7301 | * @param reason the reason the allowed network type change is taking place |
| 7302 | * @param allowedNetworkTypes the allowed network types. |
| 7303 | * @return true on success; false on any failure. |
| 7304 | */ |
| 7305 | @Override |
| 7306 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7307 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7308 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7310 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7311 | // If the caller only has carrier privileges, then they should not be able to override |
| 7312 | // any network types which were set for security reasons. |
| 7313 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7314 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7315 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7316 | throw new SecurityException( |
| 7317 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7318 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7319 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7320 | |
| 7321 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7322 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7323 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7324 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7325 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7326 | return false; |
| 7327 | } |
| 7328 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7329 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7330 | return false; |
| 7331 | } |
| 7332 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7333 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7334 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7335 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7336 | Phone phone = getPhone(subId); |
| 7337 | if (phone == null) { |
| 7338 | return false; |
| 7339 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7340 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7341 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7342 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7343 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7344 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7345 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7346 | final long identity = Binder.clearCallingIdentity(); |
| 7347 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7348 | Boolean success = (Boolean) sendRequest( |
| 7349 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7350 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7351 | |
| 7352 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7353 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7354 | } finally { |
| 7355 | Binder.restoreCallingIdentity(identity); |
| 7356 | } |
| 7357 | } |
| 7358 | |
| 7359 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7360 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7361 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7362 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7363 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7364 | * @hide |
| 7365 | */ |
| 7366 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7367 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7368 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7369 | |
| 7370 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7371 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7372 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7374 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7375 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7376 | if (phone != null) { |
| 7377 | return phone.hasMatchedTetherApnSetting(); |
| 7378 | } else { |
| 7379 | return false; |
| 7380 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7381 | } finally { |
| 7382 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7383 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7384 | } |
| 7385 | |
| 7386 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7387 | * Get the user enabled state of Mobile Data. |
| 7388 | * |
| 7389 | * TODO: remove and use isUserDataEnabled. |
| 7390 | * This can't be removed now because some vendor codes |
| 7391 | * calls through ITelephony directly while they should |
| 7392 | * use TelephonyManager. |
| 7393 | * |
| 7394 | * @return true on enabled |
| 7395 | */ |
| 7396 | @Override |
| 7397 | public boolean getDataEnabled(int subId) { |
| 7398 | return isUserDataEnabled(subId); |
| 7399 | } |
| 7400 | |
| 7401 | /** |
| 7402 | * Get whether mobile data is enabled per user setting. |
| 7403 | * |
| 7404 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7405 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7406 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7407 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7408 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7409 | * |
| 7410 | * @return {@code true} if data is enabled else {@code false} |
| 7411 | */ |
| 7412 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7413 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7414 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7415 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7416 | try { |
| 7417 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7418 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7419 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7420 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7421 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7422 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7423 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7424 | mApp, subId, functionName); |
| 7425 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7426 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7427 | |
| 7428 | final long identity = Binder.clearCallingIdentity(); |
| 7429 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7430 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7431 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7432 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7433 | if (phone != null) { |
| 7434 | boolean retVal = phone.isUserDataEnabled(); |
| 7435 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7436 | return retVal; |
| 7437 | } else { |
| 7438 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7439 | return false; |
| 7440 | } |
| 7441 | } finally { |
| 7442 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7443 | } |
| 7444 | } |
| 7445 | |
| 7446 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7447 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7448 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7449 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7450 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7451 | * @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] | 7452 | */ |
| 7453 | @Override |
| 7454 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7455 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7456 | try { |
| 7457 | try { |
| 7458 | mApp.enforceCallingOrSelfPermission( |
| 7459 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7460 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7461 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7462 | try { |
| 7463 | mApp.enforceCallingOrSelfPermission( |
| 7464 | android.Manifest.permission.READ_PHONE_STATE, |
| 7465 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7466 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7467 | mApp.enforceCallingOrSelfPermission( |
| 7468 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7469 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7470 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7471 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7472 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7474 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7475 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7476 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7477 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7478 | final long identity = Binder.clearCallingIdentity(); |
| 7479 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7480 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7482 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7483 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7484 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7485 | return retVal; |
| 7486 | } else { |
| 7487 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7488 | return false; |
| 7489 | } |
| 7490 | } finally { |
| 7491 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7492 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7493 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7494 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7495 | /** |
| 7496 | * Check if data is enabled for a specific reason |
| 7497 | * @param subId Subscription index |
| 7498 | * @param reason the reason the data enable change is taking place |
| 7499 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7500 | */ |
| 7501 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7502 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7503 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7504 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7505 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7506 | try { |
| 7507 | mApp.enforceCallingOrSelfPermission( |
| 7508 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7509 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7510 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7511 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7512 | functionName); |
| 7513 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7514 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7515 | try { |
| 7516 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7517 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7518 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7520 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7521 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7522 | } |
| 7523 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7524 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7525 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7526 | |
| 7527 | final long identity = Binder.clearCallingIdentity(); |
| 7528 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7529 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7530 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7531 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7532 | + " reason=" + reason); |
| 7533 | } |
| 7534 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7535 | if (phone != null) { |
| 7536 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7537 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7538 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7539 | return retVal; |
| 7540 | } else { |
| 7541 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7542 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7543 | + subId + " retVal=false"); |
| 7544 | } |
| 7545 | return false; |
| 7546 | } |
| 7547 | } finally { |
| 7548 | Binder.restoreCallingIdentity(identity); |
| 7549 | } |
| 7550 | } |
| 7551 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7552 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7553 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7554 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7555 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7556 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7557 | // No permission needed; this only lets the caller inspect their own status. |
| 7558 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7559 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7560 | |
| 7561 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7562 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7563 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7564 | |
| 7565 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7566 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7567 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7568 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7569 | } |
| 7570 | |
| 7571 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7572 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7573 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7574 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7575 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7576 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7577 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7578 | if (cpt == null) { |
| 7579 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7580 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7581 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7582 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7583 | } |
| 7584 | |
| 7585 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7586 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7587 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7588 | |
| 7589 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7590 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7591 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7592 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7593 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7594 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7595 | Phone phone = getPhone(subId); |
| 7596 | if (phone == null) { |
| 7597 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7598 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7599 | } |
| 7600 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7601 | if (cpt == null) { |
| 7602 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7603 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7604 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7605 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7606 | } |
| 7607 | |
| 7608 | @Override |
| 7609 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7610 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7611 | |
| 7612 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7613 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7614 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7615 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7616 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7617 | } |
| 7618 | |
| 7619 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7620 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7621 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7622 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7623 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7624 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7625 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7626 | if (phone == null) { |
| 7627 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7628 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7629 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7630 | if (cpt == null) { |
| 7631 | continue; |
| 7632 | } |
| 7633 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7634 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7635 | break; |
| 7636 | } |
| 7637 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7638 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7639 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7640 | |
| 7641 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7642 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7643 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7644 | |
| 7645 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7646 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7647 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7648 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7649 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7650 | if (phone == null) { |
| 7651 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7652 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7653 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7654 | if (cpt == null) { |
| 7655 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7656 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7657 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7658 | } |
| 7659 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7660 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7661 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7662 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7663 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7664 | if (phone == null) { |
| 7665 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7666 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7667 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7668 | if (cpt == null) { |
| 7669 | return Collections.emptyList(); |
| 7670 | } |
| 7671 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7672 | } |
| 7673 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7674 | @Override |
| 7675 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7676 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7677 | |
| 7678 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7679 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7680 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7681 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7682 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7683 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7684 | try { |
| 7685 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7686 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7687 | } |
| 7688 | } finally { |
| 7689 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7690 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7691 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7694 | @Override |
| 7695 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7696 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7697 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7698 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7699 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7700 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7701 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7702 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7703 | if (phone == null) { |
| 7704 | return null; |
| 7705 | } |
| 7706 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7707 | if (cpt == null) { |
| 7708 | return null; |
| 7709 | } |
| 7710 | return cpt.getCarrierServicePackageName(); |
| 7711 | } |
| 7712 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7713 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7714 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7715 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7716 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7717 | return null; |
| 7718 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7719 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7720 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7721 | return null; |
| 7722 | } |
| 7723 | return iccId; |
| 7724 | } |
| 7725 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7726 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7727 | public void setCallComposerStatus(int subId, int status) { |
| 7728 | enforceModifyPermission(); |
| 7729 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7730 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7731 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7732 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7733 | final long identity = Binder.clearCallingIdentity(); |
| 7734 | try { |
| 7735 | Phone phone = getPhone(subId); |
| 7736 | if (phone != null) { |
| 7737 | Phone defaultPhone = phone.getImsPhone(); |
| 7738 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7739 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7740 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7741 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7742 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7743 | } |
| 7744 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7745 | } catch (ImsException e) { |
| 7746 | throw new ServiceSpecificException(e.getCode()); |
| 7747 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7748 | Binder.restoreCallingIdentity(identity); |
| 7749 | } |
| 7750 | } |
| 7751 | |
| 7752 | @Override |
| 7753 | public int getCallComposerStatus(int subId) { |
| 7754 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7755 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7756 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7757 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7758 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7759 | final long identity = Binder.clearCallingIdentity(); |
| 7760 | try { |
| 7761 | Phone phone = getPhone(subId); |
| 7762 | if (phone != null) { |
| 7763 | Phone defaultPhone = phone.getImsPhone(); |
| 7764 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7765 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7766 | return imsPhone.getCallComposerStatus(); |
| 7767 | } |
| 7768 | } |
| 7769 | } finally { |
| 7770 | Binder.restoreCallingIdentity(identity); |
| 7771 | } |
| 7772 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7773 | } |
| 7774 | |
| 7775 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7776 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7777 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7778 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7779 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7780 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7781 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7782 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7783 | "setLine1NumberForDisplayForSubscriber"); |
| 7784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7785 | final long identity = Binder.clearCallingIdentity(); |
| 7786 | try { |
| 7787 | final String iccId = getIccId(subId); |
| 7788 | final Phone phone = getPhone(subId); |
| 7789 | if (phone == null) { |
| 7790 | return false; |
| 7791 | } |
| 7792 | final String subscriberId = phone.getSubscriberId(); |
| 7793 | |
| 7794 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7795 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7796 | + subscriberId + " to " + number); |
| 7797 | } |
| 7798 | |
| 7799 | if (TextUtils.isEmpty(iccId)) { |
| 7800 | return false; |
| 7801 | } |
| 7802 | |
| 7803 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7804 | |
| 7805 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7806 | if (alphaTag == null) { |
| 7807 | editor.remove(alphaTagPrefKey); |
| 7808 | } else { |
| 7809 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7810 | } |
| 7811 | |
| 7812 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7813 | // track all merged IMSIs based on line number |
| 7814 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7815 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7816 | if (number == null) { |
| 7817 | editor.remove(numberPrefKey); |
| 7818 | editor.remove(subscriberPrefKey); |
| 7819 | } else { |
| 7820 | editor.putString(numberPrefKey, number); |
| 7821 | editor.putString(subscriberPrefKey, subscriberId); |
| 7822 | } |
| 7823 | |
| 7824 | editor.commit(); |
| 7825 | return true; |
| 7826 | } finally { |
| 7827 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7828 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7829 | } |
| 7830 | |
| 7831 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7832 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7833 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7834 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7835 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7836 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7837 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7838 | return null; |
| 7839 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7840 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7841 | enforceTelephonyFeatureWithException(callingPackage, |
| 7842 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7843 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7844 | final long identity = Binder.clearCallingIdentity(); |
| 7845 | try { |
| 7846 | String iccId = getIccId(subId); |
| 7847 | if (iccId != null) { |
| 7848 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7849 | if (DBG_MERGE) { |
| 7850 | log("getLine1NumberForDisplay returning " |
| 7851 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7852 | } |
| 7853 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7854 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7855 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7856 | return null; |
| 7857 | } finally { |
| 7858 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7859 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7860 | } |
| 7861 | |
| 7862 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7863 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7864 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7865 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7866 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7867 | return null; |
| 7868 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7869 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7870 | final long identity = Binder.clearCallingIdentity(); |
| 7871 | try { |
| 7872 | String iccId = getIccId(subId); |
| 7873 | if (iccId != null) { |
| 7874 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7875 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7876 | } |
| 7877 | return null; |
| 7878 | } finally { |
| 7879 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7880 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7881 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7882 | |
| 7883 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7884 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7885 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7886 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7887 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7888 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7889 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7890 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7891 | return null; |
| 7892 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7893 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7894 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7895 | // the process, where TelephonyManager was instantiated. |
| 7896 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7897 | final long identity = Binder.clearCallingIdentity(); |
| 7898 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7899 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7900 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7901 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7902 | |
| 7903 | // Figure out what subscribers are currently active |
| 7904 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7905 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7906 | // Only consider subs which match the current subId |
| 7907 | // This logic can be simplified. See b/131189269 for progress. |
| 7908 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7909 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7911 | |
| 7912 | // First pass, find a number override for an active subscriber |
| 7913 | String mergeNumber = null; |
| 7914 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7915 | for (String key : prefs.keySet()) { |
| 7916 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7917 | final String subscriberId = (String) prefs.get(key); |
| 7918 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7919 | final String iccId = key.substring( |
| 7920 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7921 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7922 | mergeNumber = (String) prefs.get(numberKey); |
| 7923 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7924 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7925 | + " for active subscriber " + subscriberId); |
| 7926 | } |
| 7927 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7928 | break; |
| 7929 | } |
| 7930 | } |
| 7931 | } |
| 7932 | } |
| 7933 | |
| 7934 | // Shortcut when no active merged subscribers |
| 7935 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7936 | return null; |
| 7937 | } |
| 7938 | |
| 7939 | // Second pass, find all subscribers under that line override |
| 7940 | final ArraySet<String> result = new ArraySet<>(); |
| 7941 | for (String key : prefs.keySet()) { |
| 7942 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7943 | final String number = (String) prefs.get(key); |
| 7944 | if (mergeNumber.equals(number)) { |
| 7945 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7946 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7947 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7948 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7949 | result.add(subscriberId); |
| 7950 | } |
| 7951 | } |
| 7952 | } |
| 7953 | } |
| 7954 | |
| 7955 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7956 | Arrays.sort(resultArray); |
| 7957 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7958 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7959 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7960 | } |
| 7961 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7962 | } finally { |
| 7963 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7964 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7965 | } |
| 7966 | |
| 7967 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7968 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7969 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7970 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7971 | enforceTelephonyFeatureWithException(callingPackage, |
| 7972 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 7973 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7974 | final long identity = Binder.clearCallingIdentity(); |
| 7975 | try { |
| 7976 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7977 | TelephonyManager.class); |
| 7978 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7979 | if (subscriberId == null) { |
| 7980 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7981 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7982 | + subId); |
| 7983 | } |
| 7984 | return null; |
| 7985 | } |
| 7986 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7987 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7988 | .getSubscriptionInfo(subId); |
| 7989 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7990 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7991 | if (groupUuid == null) { |
| 7992 | return new String[]{subscriberId}; |
| 7993 | } |
| 7994 | |
| 7995 | // Get all subscriberIds from the group. |
| 7996 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7997 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7998 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7999 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8000 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8001 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8002 | if (subscriberId != null) { |
| 8003 | mergedSubscriberIds.add(subscriberId); |
| 8004 | } |
| 8005 | } |
| 8006 | |
| 8007 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8008 | } finally { |
| 8009 | Binder.restoreCallingIdentity(identity); |
| 8010 | |
| 8011 | } |
| 8012 | } |
| 8013 | |
| 8014 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8015 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8016 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8017 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8019 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8020 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8021 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8022 | final long identity = Binder.clearCallingIdentity(); |
| 8023 | try { |
| 8024 | final Phone phone = getPhone(subId); |
| 8025 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8026 | } finally { |
| 8027 | Binder.restoreCallingIdentity(identity); |
| 8028 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8029 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8030 | |
| 8031 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8032 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8033 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8034 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8035 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8036 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8037 | |
| 8038 | final long identity = Binder.clearCallingIdentity(); |
| 8039 | try { |
| 8040 | final Phone phone = getPhone(subId); |
| 8041 | if (phone == null) { |
| 8042 | return false; |
| 8043 | } |
| 8044 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8045 | cdmaNonRoamingList); |
| 8046 | } finally { |
| 8047 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8048 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8049 | } |
| 8050 | |
| 8051 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8052 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8053 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8054 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8055 | if (phone == null) { |
| 8056 | return raf; |
| 8057 | } |
| 8058 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8059 | try { |
| 8060 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8061 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8062 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8063 | } catch (SecurityException e) { |
| 8064 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8065 | throw e; |
| 8066 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8067 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8068 | enforceTelephonyFeatureWithException(callingPackage, |
| 8069 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8071 | final long identity = Binder.clearCallingIdentity(); |
| 8072 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8073 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8074 | } finally { |
| 8075 | Binder.restoreCallingIdentity(identity); |
| 8076 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8077 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8078 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8079 | |
| 8080 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8081 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8082 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8083 | try { |
| 8084 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8085 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8086 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8087 | } |
| 8088 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8089 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8090 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8091 | |
| 8092 | enforceTelephonyFeatureWithException(callingPackage, |
| 8093 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8094 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8095 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8096 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8097 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8098 | throw new SecurityException("App must be the dialer role holder to" |
| 8099 | + " upload a call composer pic"); |
| 8100 | } |
| 8101 | |
| 8102 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8103 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8104 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8105 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8106 | boolean readUntilEnd = false; |
| 8107 | int totalBytesRead = 0; |
| 8108 | byte[] buffer = new byte[16 * 1024]; |
| 8109 | while (true) { |
| 8110 | int numRead; |
| 8111 | try { |
| 8112 | numRead = input.read(buffer); |
| 8113 | } catch (IOException e) { |
| 8114 | try { |
| 8115 | fd.checkError(); |
| 8116 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8117 | null); |
| 8118 | } catch (IOException e1) { |
| 8119 | // This means that the other side closed explicitly with an error. If this |
| 8120 | // happens, log and ignore. |
| 8121 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8122 | } |
| 8123 | break; |
| 8124 | } |
| 8125 | if (numRead == -1) { |
| 8126 | readUntilEnd = true; |
| 8127 | break; |
| 8128 | } |
| 8129 | totalBytesRead += numRead; |
| 8130 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8131 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8132 | try { |
| 8133 | input.close(); |
| 8134 | } catch (IOException e) { |
| 8135 | // ignore |
| 8136 | } |
| 8137 | break; |
| 8138 | } |
| 8139 | output.write(buffer, 0, numRead); |
| 8140 | } |
| 8141 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8142 | // close is above, where the picture size is too big. |
| 8143 | |
| 8144 | try { |
| 8145 | fd.checkError(); |
| 8146 | } catch (IOException e) { |
| 8147 | loge("Remote end for call composer closed with an error: " + e); |
| 8148 | return; |
| 8149 | } |
| 8150 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8151 | if (!readUntilEnd) { |
| 8152 | loge("Did not finish reading entire image; aborting"); |
| 8153 | return; |
| 8154 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8155 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8156 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8157 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8158 | new CallComposerPictureTransfer.Factory() {}, |
| 8159 | imageData, |
| 8160 | (result) -> { |
| 8161 | if (result.first != null) { |
| 8162 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8163 | Bundle outputResult = new Bundle(); |
| 8164 | outputResult.putParcelable( |
| 8165 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8166 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8167 | outputResult); |
| 8168 | } else { |
| 8169 | callback.send(result.second, null); |
| 8170 | } |
| 8171 | } |
| 8172 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8173 | }); |
| 8174 | } |
| 8175 | |
| 8176 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8177 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8178 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8179 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8180 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8181 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8182 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8183 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8184 | final long identity = Binder.clearCallingIdentity(); |
| 8185 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8186 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8187 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8188 | } finally { |
| 8189 | Binder.restoreCallingIdentity(identity); |
| 8190 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8191 | } |
| 8192 | |
| 8193 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8194 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8195 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8196 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8197 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8198 | return false; |
| 8199 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8200 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8201 | enforceTelephonyFeatureWithException(callingPackage, |
| 8202 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8203 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8204 | final long identity = Binder.clearCallingIdentity(); |
| 8205 | try { |
| 8206 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8207 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8208 | // In the long run, we may instead need to check if there exists a connection service |
| 8209 | // which can support video calling. |
| 8210 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8211 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8212 | return imsManager.isVtEnabledByPlatform() |
| 8213 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8214 | && imsManager.isVtEnabledByUser(); |
| 8215 | } finally { |
| 8216 | Binder.restoreCallingIdentity(identity); |
| 8217 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8218 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8219 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8220 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8221 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8222 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8224 | mApp, subId, callingPackage, callingFeatureId, |
| 8225 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8226 | return false; |
| 8227 | } |
| 8228 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8229 | enforceTelephonyFeatureWithException(callingPackage, |
| 8230 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8231 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8232 | final long identity = Binder.clearCallingIdentity(); |
| 8233 | try { |
| 8234 | CarrierConfigManager configManager = |
| 8235 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8236 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8237 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8238 | } finally { |
| 8239 | Binder.restoreCallingIdentity(identity); |
| 8240 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8241 | } |
| 8242 | |
| 8243 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8244 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8245 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8246 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8247 | return false; |
| 8248 | } |
| 8249 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8250 | enforceTelephonyFeatureWithException(callingPackage, |
| 8251 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8252 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8253 | final long identity = Binder.clearCallingIdentity(); |
| 8254 | try { |
| 8255 | CarrierConfigManager configManager = |
| 8256 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8257 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8258 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8259 | } finally { |
| 8260 | Binder.restoreCallingIdentity(identity); |
| 8261 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8262 | } |
| 8263 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8264 | @Override |
| 8265 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8266 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8267 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8268 | } |
| 8269 | |
| 8270 | @Override |
| 8271 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8272 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8273 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8274 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8277 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8278 | } finally { |
| 8279 | Binder.restoreCallingIdentity(identity); |
| 8280 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8281 | } |
| 8282 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8283 | /** |
| 8284 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8285 | * support for the feature and device firmware support. |
| 8286 | * |
| 8287 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8288 | */ |
| 8289 | @Override |
| 8290 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8291 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8292 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8293 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8294 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8295 | final Phone phone = getPhone(subscriptionId); |
| 8296 | if (phone == null) { |
| 8297 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8298 | return false; |
| 8299 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8300 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8301 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8302 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8303 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8304 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8305 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8306 | return isCarrierSupported && isDeviceSupported; |
| 8307 | } finally { |
| 8308 | Binder.restoreCallingIdentity(identity); |
| 8309 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8310 | } |
| 8311 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8312 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8313 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8314 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8315 | * 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] | 8316 | */ |
| 8317 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8318 | final long identity = Binder.clearCallingIdentity(); |
| 8319 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8320 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8321 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8322 | return false; |
| 8323 | } |
| 8324 | } |
| 8325 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8326 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8327 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8328 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8329 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8330 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8331 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8332 | } finally { |
| 8333 | Binder.restoreCallingIdentity(identity); |
| 8334 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8335 | } |
| 8336 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8337 | @Deprecated |
| 8338 | @Override |
| 8339 | public String getDeviceId(String callingPackage) { |
| 8340 | return getDeviceIdWithFeature(callingPackage, null); |
| 8341 | } |
| 8342 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8343 | /** |
| 8344 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8345 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8346 | * |
| 8347 | * <p>Requires Permission: |
| 8348 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8349 | */ |
| 8350 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8351 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8352 | try { |
| 8353 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8354 | } catch (SecurityException se) { |
| 8355 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8356 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8357 | + Binder.getCallingUid()); |
| 8358 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8359 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8360 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8361 | return null; |
| 8362 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8363 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8364 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8365 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8366 | return null; |
| 8367 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8368 | |
| 8369 | final long identity = Binder.clearCallingIdentity(); |
| 8370 | try { |
| 8371 | return phone.getDeviceId(); |
| 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
| 8374 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8375 | } |
| 8376 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8377 | /** |
| 8378 | * {@hide} |
| 8379 | * Returns the IMS Registration Status on a particular subid |
| 8380 | * |
| 8381 | * @param subId |
| 8382 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8383 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8384 | Phone phone = getPhone(subId); |
| 8385 | if (phone != null) { |
| 8386 | return phone.isImsRegistered(); |
| 8387 | } else { |
| 8388 | return false; |
| 8389 | } |
| 8390 | } |
| 8391 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8392 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8393 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8394 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8395 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8396 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8397 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8398 | } |
| 8399 | final long identity = Binder.clearCallingIdentity(); |
| 8400 | try { |
| 8401 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8402 | } finally { |
| 8403 | Binder.restoreCallingIdentity(identity); |
| 8404 | } |
| 8405 | } |
| 8406 | |
| 8407 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8408 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8409 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8410 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8411 | mApp, |
| 8412 | subscriptionId, |
| 8413 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8414 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8415 | |
| 8416 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8417 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8418 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8419 | final long identity = Binder.clearCallingIdentity(); |
| 8420 | try { |
| 8421 | Phone phone = getPhone(subscriptionId); |
| 8422 | if (phone == null) { |
| 8423 | return null; |
| 8424 | } |
| 8425 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8426 | } finally { |
| 8427 | Binder.restoreCallingIdentity(identity); |
| 8428 | } |
| 8429 | } |
| 8430 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8431 | /** |
| 8432 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8433 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8434 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8435 | final long identity = Binder.clearCallingIdentity(); |
| 8436 | try { |
| 8437 | Phone phone = getPhone(subId); |
| 8438 | if (phone != null) { |
| 8439 | return phone.isWifiCallingEnabled(); |
| 8440 | } else { |
| 8441 | return false; |
| 8442 | } |
| 8443 | } finally { |
| 8444 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8445 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8446 | } |
| 8447 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8448 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8449 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8450 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8451 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8452 | final long identity = Binder.clearCallingIdentity(); |
| 8453 | try { |
| 8454 | Phone phone = getPhone(subId); |
| 8455 | if (phone != null) { |
| 8456 | return phone.isVideoEnabled(); |
| 8457 | } else { |
| 8458 | return false; |
| 8459 | } |
| 8460 | } finally { |
| 8461 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8462 | } |
| 8463 | } |
| 8464 | |
| 8465 | /** |
| 8466 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8467 | * defined in {@link ImsRegistrationImplBase}. |
| 8468 | */ |
| 8469 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | final long identity = Binder.clearCallingIdentity(); |
| 8471 | try { |
| 8472 | Phone phone = getPhone(subId); |
| 8473 | if (phone != null) { |
| 8474 | return phone.getImsRegistrationTech(); |
| 8475 | } else { |
| 8476 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8477 | } |
| 8478 | } finally { |
| 8479 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8480 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8481 | } |
| 8482 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8483 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8484 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8485 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8486 | |
| 8487 | enforceTelephonyFeatureWithException(callingPackage, |
| 8488 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8489 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8490 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8491 | return; |
| 8492 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8493 | Phone defaultPhone = getDefaultPhone(); |
| 8494 | if (defaultPhone != null) { |
| 8495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8496 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8497 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8498 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8499 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8500 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8501 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8502 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8503 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8504 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8505 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8506 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8507 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8508 | setDataRoamingEnabled(subId, phone == null ? false |
| 8509 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8510 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8511 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8512 | // There has been issues when Sms raw table somehow stores orphan |
| 8513 | // fragments. They lead to garbled message when new fragments come |
| 8514 | // in and combined with those stale ones. In case this happens again, |
| 8515 | // user can reset all network settings which will clean up this table. |
| 8516 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8517 | // Clean up IMS settings as well here. |
| 8518 | int slotId = getSlotIndex(subId); |
| 8519 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8520 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8521 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8522 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8523 | if (defaultPhone == null) { |
| 8524 | return; |
| 8525 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8526 | // Erase modem config if erase modem on network setting is enabled. |
| 8527 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8528 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8529 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8530 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8531 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8532 | |
| 8533 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8534 | } finally { |
| 8535 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8536 | } |
| 8537 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8538 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8539 | @VisibleForTesting |
| 8540 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8541 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8542 | return; |
| 8543 | } |
| 8544 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8545 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8546 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8547 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8548 | "user=" + defaultNetworkType); |
| 8549 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8550 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8551 | defaultNetworkType, null); |
| 8552 | } |
| 8553 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8554 | private void cleanUpSmsRawTable(Context context) { |
| 8555 | ContentResolver resolver = context.getContentResolver(); |
| 8556 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8557 | resolver.delete(uri, null, null); |
| 8558 | } |
| 8559 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8560 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8561 | public String getSimLocaleForSubscriber(int subId) { |
| 8562 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8563 | |
| 8564 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8565 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8566 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8567 | final Phone phone = getPhone(subId); |
| 8568 | if (phone == null) { |
| 8569 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8570 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8571 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8572 | final long identity = Binder.clearCallingIdentity(); |
| 8573 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8574 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8575 | phone.getContext().getOpPackageName(), |
| 8576 | phone.getContext().getAttributionTag()); |
| 8577 | if (info == null) { |
| 8578 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8579 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8580 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8581 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8582 | // preferences (EF-PL and EF-LI)... |
| 8583 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8584 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8585 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8586 | if (localeFromDefaultSim != null) { |
| 8587 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8588 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8589 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8590 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8591 | } else { |
| 8592 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8593 | } |
| 8594 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8595 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8596 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8597 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8598 | // the SIM and carrier preferences does not include a country we add the country |
| 8599 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8600 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8601 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8602 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8603 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8604 | } |
| 8605 | |
| 8606 | if (DBG) log("No locale found - returning null"); |
| 8607 | return null; |
| 8608 | } finally { |
| 8609 | Binder.restoreCallingIdentity(identity); |
| 8610 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8611 | } |
| 8612 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8613 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8614 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8615 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8616 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8617 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8618 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8619 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8620 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8621 | return localeTag; |
| 8622 | } |
| 8623 | } |
| 8624 | return inputLocale.toLanguageTag(); |
| 8625 | } |
| 8626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8627 | /** |
| 8628 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8629 | */ |
| 8630 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8631 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8632 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8633 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8634 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8635 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8636 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8637 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8638 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8639 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8640 | * representing the state of the modem. |
| 8641 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8642 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8643 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8644 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8645 | */ |
| 8646 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8647 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8648 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8649 | |
| 8650 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8651 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8652 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8653 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8654 | |
| 8655 | final long identity = Binder.clearCallingIdentity(); |
| 8656 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8657 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8658 | } finally { |
| 8659 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8660 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8661 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8662 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8663 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8664 | // less than total activity duration. |
| 8665 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8666 | if (info == null) { |
| 8667 | return false; |
| 8668 | } |
| 8669 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8670 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8671 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8672 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8673 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8674 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8675 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8676 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8677 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8678 | } |
| 8679 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8680 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8681 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8682 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8683 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8684 | |
| 8685 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8686 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8687 | } |
| 8688 | |
| 8689 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8690 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8691 | rat, |
| 8692 | freq, |
| 8693 | info.getReceiveTimeMillis(rat, freq) |
| 8694 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8695 | } |
| 8696 | |
| 8697 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8698 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8699 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8700 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8701 | |
| 8702 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8703 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8704 | } |
| 8705 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8706 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8707 | rat, |
| 8708 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8709 | } |
| 8710 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8711 | /** |
| 8712 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8713 | * @param info recent ModemActivityInfo |
| 8714 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8715 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8716 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8717 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8718 | boolean matched; |
| 8719 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8720 | matched = false; |
| 8721 | int rat = info.getSpecificInfoRat(i); |
| 8722 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8723 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8724 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8725 | //if it already exists |
| 8726 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8727 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8728 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8729 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8730 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8731 | updateLastModemActivityInfo(info, rat, freq); |
| 8732 | matched = true; |
| 8733 | } |
| 8734 | } else { |
| 8735 | updateLastModemActivityInfo(info, rat); |
| 8736 | matched = true; |
| 8737 | } |
| 8738 | } |
| 8739 | } |
| 8740 | |
| 8741 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8742 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8743 | new ActivityStatsTechSpecificInfo( |
| 8744 | rat, |
| 8745 | freq, |
| 8746 | info.getTransmitTimeMillis(rat, freq), |
| 8747 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8748 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8749 | } |
| 8750 | } |
| 8751 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8752 | mLastModemActivitySpecificInfo = |
| 8753 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8754 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8755 | |
| 8756 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8757 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8758 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8759 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8760 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8761 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8762 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8763 | |
| 8764 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8765 | new ModemActivityInfo( |
| 8766 | mLastModemActivityInfo.getTimestampMillis(), |
| 8767 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8768 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8769 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8770 | } |
| 8771 | |
| 8772 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8773 | ActivityStatsTechSpecificInfo[] info) { |
| 8774 | int infoSize = info.length; |
| 8775 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8776 | for (int i = 0; i < infoSize; i++) { |
| 8777 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8778 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8779 | info[i].getTransmitTimeMillis(), |
| 8780 | (int) info[i].getReceiveTimeMillis()); |
| 8781 | } |
| 8782 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8783 | } |
| 8784 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8785 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8786 | * Returns the service state information on specified subscription. |
| 8787 | */ |
| 8788 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8789 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8790 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8791 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8792 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8793 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8794 | return null; |
| 8795 | } |
| 8796 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8797 | enforceTelephonyFeatureWithException(callingPackage, |
| 8798 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8799 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8800 | boolean hasFinePermission = false; |
| 8801 | boolean hasCoarsePermission = false; |
| 8802 | if (!renounceFineLocationAccess) { |
| 8803 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8804 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8805 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8806 | .setCallingPackage(callingPackage) |
| 8807 | .setCallingFeatureId(callingFeatureId) |
| 8808 | .setCallingPid(Binder.getCallingPid()) |
| 8809 | .setCallingUid(Binder.getCallingUid()) |
| 8810 | .setMethod("getServiceStateForSubscriber") |
| 8811 | .setLogAsInfo(true) |
| 8812 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8813 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8814 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8815 | .build()); |
| 8816 | hasFinePermission = |
| 8817 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8818 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8819 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8820 | if (!renounceCoarseLocationAccess) { |
| 8821 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8822 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8823 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8824 | .setCallingPackage(callingPackage) |
| 8825 | .setCallingFeatureId(callingFeatureId) |
| 8826 | .setCallingPid(Binder.getCallingPid()) |
| 8827 | .setCallingUid(Binder.getCallingUid()) |
| 8828 | .setMethod("getServiceStateForSubscriber") |
| 8829 | .setLogAsInfo(true) |
| 8830 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8831 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8832 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8833 | .build()); |
| 8834 | hasCoarsePermission = |
| 8835 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8836 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8837 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8838 | final Phone phone = getPhone(subId); |
| 8839 | if (phone == null) { |
| 8840 | return null; |
| 8841 | } |
| 8842 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8843 | final long identity = Binder.clearCallingIdentity(); |
| 8844 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8845 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8846 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8847 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8848 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8849 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8850 | .getSubscriptionInfoInternal(subId); |
| 8851 | if (subInfo == null || !subInfo.isActive()) { |
| 8852 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8853 | + "subId=" + subId); |
| 8854 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8855 | } |
| 8856 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8857 | ServiceState ss = phone.getServiceState(); |
| 8858 | |
| 8859 | // Scrub out the location info in ServiceState depending on what level of access |
| 8860 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8861 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8862 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8863 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8864 | } finally { |
| 8865 | Binder.restoreCallingIdentity(identity); |
| 8866 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8867 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8868 | |
| 8869 | /** |
| 8870 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8871 | * |
| 8872 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8873 | * voicemail ringtone. |
| 8874 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8875 | * PhoneAccount. |
| 8876 | */ |
| 8877 | @Override |
| 8878 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8879 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8880 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8882 | final long identity = Binder.clearCallingIdentity(); |
| 8883 | try { |
| 8884 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8885 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8886 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8887 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8888 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8889 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8890 | } finally { |
| 8891 | Binder.restoreCallingIdentity(identity); |
| 8892 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8893 | } |
| 8894 | |
| 8895 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8896 | * Sets the per-account voicemail ringtone. |
| 8897 | * |
| 8898 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8899 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8900 | * |
| 8901 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8902 | * voicemail ringtone. |
| 8903 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8904 | * PhoneAccount. |
| 8905 | */ |
| 8906 | @Override |
| 8907 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8908 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8909 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8910 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8911 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8912 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8914 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8915 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8916 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8917 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8918 | enforceTelephonyFeatureWithException(callingPackage, |
| 8919 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8920 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8921 | final long identity = Binder.clearCallingIdentity(); |
| 8922 | try { |
| 8923 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8924 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8925 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8926 | } |
| 8927 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8928 | } finally { |
| 8929 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8930 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8931 | } |
| 8932 | |
| 8933 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8934 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8935 | * |
| 8936 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8937 | * voicemail vibration setting. |
| 8938 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8939 | */ |
| 8940 | @Override |
| 8941 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8942 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8943 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8945 | final long identity = Binder.clearCallingIdentity(); |
| 8946 | try { |
| 8947 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8948 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8949 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8950 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8952 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8953 | } finally { |
| 8954 | Binder.restoreCallingIdentity(identity); |
| 8955 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8956 | } |
| 8957 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8958 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8959 | * Sets the per-account voicemail vibration. |
| 8960 | * |
| 8961 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8962 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8963 | * |
| 8964 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8965 | * voicemail vibration setting. |
| 8966 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8967 | * specific PhoneAccount. |
| 8968 | */ |
| 8969 | @Override |
| 8970 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8971 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8972 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8973 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8974 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8975 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8977 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8978 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8979 | } |
| 8980 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8981 | enforceTelephonyFeatureWithException(callingPackage, |
| 8982 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 8983 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8984 | final long identity = Binder.clearCallingIdentity(); |
| 8985 | try { |
| 8986 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8987 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8988 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8989 | } |
| 8990 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8991 | } finally { |
| 8992 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8993 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8994 | } |
| 8995 | |
| 8996 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8997 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8998 | * |
| 8999 | * @throws SecurityException if the caller does not have the required permission |
| 9000 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9001 | @VisibleForTesting |
| 9002 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9003 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9004 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9005 | } |
| 9006 | |
| 9007 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9008 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9009 | * permission. |
| 9010 | * |
| 9011 | * @throws SecurityException if the caller does not have the required permission |
| 9012 | */ |
| 9013 | private void enforceSendSmsPermission() { |
| 9014 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9015 | } |
| 9016 | |
| 9017 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9018 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9019 | * users permission. |
| 9020 | * |
| 9021 | * @throws SecurityException if the caller does not have the required permission |
| 9022 | */ |
| 9023 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9024 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9025 | } |
| 9026 | |
| 9027 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9028 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9029 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9030 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9031 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9032 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9033 | final long identity = Binder.clearCallingIdentity(); |
| 9034 | try { |
| 9035 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9036 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9037 | if (componentName == null) { |
| 9038 | throw new SecurityException( |
| 9039 | "Caller not current active visual voicemail package[null]"); |
| 9040 | } |
| 9041 | String vvmPackage = componentName.getPackageName(); |
| 9042 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9043 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9044 | } |
| 9045 | } finally { |
| 9046 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9047 | } |
| 9048 | } |
| 9049 | |
| 9050 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9051 | * Return the application ID for the app type. |
| 9052 | * |
| 9053 | * @param subId the subscription ID that this request applies to. |
| 9054 | * @param appType the uicc app type. |
| 9055 | * @return Application ID for specificied app type, or null if no uicc. |
| 9056 | */ |
| 9057 | @Override |
| 9058 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9059 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9060 | |
| 9061 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9062 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9063 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9064 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9065 | |
| 9066 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9067 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9068 | if (phone == null) { |
| 9069 | return null; |
| 9070 | } |
| 9071 | String aid = null; |
| 9072 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9073 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9074 | .getApplicationByType(appType).getAid(); |
| 9075 | } catch (Exception e) { |
| 9076 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9077 | } |
| 9078 | return aid; |
| 9079 | } finally { |
| 9080 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9081 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9082 | } |
| 9083 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9084 | /** |
| 9085 | * Return the Electronic Serial Number. |
| 9086 | * |
| 9087 | * @param subId the subscription ID that this request applies to. |
| 9088 | * @return ESN or null if error. |
| 9089 | */ |
| 9090 | @Override |
| 9091 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9092 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9093 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9094 | |
| 9095 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9096 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9097 | if (phone == null) { |
| 9098 | return null; |
| 9099 | } |
| 9100 | String esn = null; |
| 9101 | try { |
| 9102 | esn = phone.getEsn(); |
| 9103 | } catch (Exception e) { |
| 9104 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9105 | } |
| 9106 | return esn; |
| 9107 | } finally { |
| 9108 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9109 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9110 | } |
| 9111 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9112 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9113 | * Return the Preferred Roaming List Version. |
| 9114 | * |
| 9115 | * @param subId the subscription ID that this request applies to. |
| 9116 | * @return PRLVersion or null if error. |
| 9117 | */ |
| 9118 | @Override |
| 9119 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9120 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9121 | |
| 9122 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9123 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9124 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9125 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9126 | |
| 9127 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9128 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9129 | if (phone == null) { |
| 9130 | return null; |
| 9131 | } |
| 9132 | String cdmaPrlVersion = null; |
| 9133 | try { |
| 9134 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9135 | } catch (Exception e) { |
| 9136 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9137 | } |
| 9138 | return cdmaPrlVersion; |
| 9139 | } finally { |
| 9140 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9141 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9142 | } |
| 9143 | |
| 9144 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9145 | * Get snapshot of Telephony histograms |
| 9146 | * @return List of Telephony histograms |
| 9147 | * @hide |
| 9148 | */ |
| 9149 | @Override |
| 9150 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9152 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9153 | |
| 9154 | final long identity = Binder.clearCallingIdentity(); |
| 9155 | try { |
| 9156 | return RIL.getTelephonyRILTimingHistograms(); |
| 9157 | } finally { |
| 9158 | Binder.restoreCallingIdentity(identity); |
| 9159 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9160 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9161 | |
| 9162 | /** |
| 9163 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9164 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9165 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9166 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9167 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9168 | * @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] | 9169 | */ |
| 9170 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9171 | @TelephonyManager.SetCarrierRestrictionResult |
| 9172 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9173 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9174 | |
| 9175 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9176 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9177 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9178 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9179 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9180 | if (carrierRestrictionRules == null) { |
| 9181 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9182 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9183 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9184 | final long identity = Binder.clearCallingIdentity(); |
| 9185 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9186 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9187 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9188 | } finally { |
| 9189 | Binder.restoreCallingIdentity(identity); |
| 9190 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9191 | } |
| 9192 | |
| 9193 | /** |
| 9194 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9195 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9196 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9197 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9198 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9199 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9200 | */ |
| 9201 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9202 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9203 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9204 | |
| 9205 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9206 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9207 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9208 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9209 | |
| 9210 | final long identity = Binder.clearCallingIdentity(); |
| 9211 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9212 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9213 | if (response instanceof CarrierRestrictionRules) { |
| 9214 | return (CarrierRestrictionRules) response; |
| 9215 | } |
| 9216 | // Response is an Exception of some kind, |
| 9217 | // which is signalled to the user as a NULL retval |
| 9218 | return null; |
| 9219 | } catch (Exception e) { |
| 9220 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9221 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9222 | } finally { |
| 9223 | Binder.restoreCallingIdentity(identity); |
| 9224 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9225 | } |
| 9226 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9227 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9228 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9229 | * through the callback. |
| 9230 | * |
| 9231 | * @param callback The callback that will be used to send the result. |
| 9232 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9233 | * the caller is not allowlisted. |
| 9234 | */ |
| 9235 | @Override |
| 9236 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9237 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9238 | |
| 9239 | enforceTelephonyFeatureWithException(packageName, |
| 9240 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9241 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9242 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9243 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9244 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9245 | throw new SecurityException("Not an authorized caller"); |
| 9246 | } |
| 9247 | final long identity = Binder.clearCallingIdentity(); |
| 9248 | try { |
| 9249 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9250 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9251 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9252 | } finally { |
| 9253 | Binder.restoreCallingIdentity(identity); |
| 9254 | } |
| 9255 | } |
| 9256 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9257 | @Override |
| 9258 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9259 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9260 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9261 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9262 | } |
| 9263 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9264 | @VisibleForTesting |
| 9265 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9266 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9267 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9268 | } |
| 9269 | |
| 9270 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9271 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9272 | * @param subId the subscription ID that this action applies to. |
| 9273 | * @param enabled control enable or disable radio. |
| 9274 | * {@hide} |
| 9275 | */ |
| 9276 | @Override |
| 9277 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9278 | enforceModifyPermission(); |
| 9279 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9280 | |
| 9281 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9282 | if (phone == null) { |
| 9283 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9284 | return; |
| 9285 | } |
| 9286 | try { |
| 9287 | phone.carrierActionSetRadioEnabled(enabled); |
| 9288 | } catch (Exception e) { |
| 9289 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9290 | } finally { |
| 9291 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9292 | } |
| 9293 | } |
| 9294 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9295 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9296 | * Enable or disable Voice over NR (VoNR) |
| 9297 | * @param subId the subscription ID that this action applies to. |
| 9298 | * @param enabled enable or disable VoNR. |
| 9299 | * @return operation result. |
| 9300 | */ |
| 9301 | @Override |
| 9302 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9303 | enforceModifyPermission(); |
| 9304 | final Phone phone = getPhone(subId); |
| 9305 | |
| 9306 | final long identity = Binder.clearCallingIdentity(); |
| 9307 | if (phone == null) { |
| 9308 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9309 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9310 | } |
| 9311 | |
| 9312 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9313 | try { |
| 9314 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9315 | workSource); |
| 9316 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9317 | |
| 9318 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9319 | if (DBG) { |
| 9320 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9321 | } |
| 9322 | SubscriptionManager.setSubscriptionProperty( |
| 9323 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9324 | (enabled ? "1" : "0")); |
| 9325 | } |
| 9326 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9327 | return result; |
| 9328 | } finally { |
| 9329 | Binder.restoreCallingIdentity(identity); |
| 9330 | } |
| 9331 | } |
| 9332 | |
| 9333 | /** |
| 9334 | * Is voice over NR enabled |
| 9335 | * @return true if VoNR is enabled else false |
| 9336 | */ |
| 9337 | @Override |
| 9338 | public boolean isVoNrEnabled(int subId) { |
| 9339 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9340 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9341 | final long identity = Binder.clearCallingIdentity(); |
| 9342 | try { |
| 9343 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9344 | null, subId, workSource); |
| 9345 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9346 | return isEnabled; |
| 9347 | } finally { |
| 9348 | Binder.restoreCallingIdentity(identity); |
| 9349 | } |
| 9350 | } |
| 9351 | |
| 9352 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9353 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9354 | * network status based on which carrier apps could apply actions accordingly, |
| 9355 | * enable/disable default url handler for example. |
| 9356 | * |
| 9357 | * @param subId the subscription ID that this action applies to. |
| 9358 | * @param report control start/stop reporting the default network status. |
| 9359 | * {@hide} |
| 9360 | */ |
| 9361 | @Override |
| 9362 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9363 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9364 | |
| 9365 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9366 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9367 | "carrierActionReportDefaultNetworkStatus"); |
| 9368 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9369 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9370 | |
| 9371 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9372 | if (phone == null) { |
| 9373 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9374 | return; |
| 9375 | } |
| 9376 | try { |
| 9377 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9378 | } catch (Exception e) { |
| 9379 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9380 | } finally { |
| 9381 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9382 | } |
| 9383 | } |
| 9384 | |
| 9385 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9386 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9387 | * @param subId the subscription ID that this action applies to. |
| 9388 | * {@hide} |
| 9389 | */ |
| 9390 | @Override |
| 9391 | public void carrierActionResetAll(int subId) { |
| 9392 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9393 | |
| 9394 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9395 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9396 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9397 | final Phone phone = getPhone(subId); |
| 9398 | if (phone == null) { |
| 9399 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9400 | return; |
| 9401 | } |
| 9402 | try { |
| 9403 | phone.carrierActionResetAll(); |
| 9404 | } catch (Exception e) { |
| 9405 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9406 | } |
| 9407 | } |
| 9408 | |
| 9409 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9410 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9411 | * bug report is being generated. |
| 9412 | */ |
| 9413 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9414 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9415 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9416 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9417 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9418 | + Binder.getCallingPid() |
| 9419 | + ", uid=" + Binder.getCallingUid() |
| 9420 | + "without permission " |
| 9421 | + android.Manifest.permission.DUMP); |
| 9422 | return; |
| 9423 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9424 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9425 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9426 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9427 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9428 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9429 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9430 | @NonNull String[] args) { |
| 9431 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9432 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9433 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9434 | } |
| 9435 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9436 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9437 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9438 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9439 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9440 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9441 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9442 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9443 | */ |
| 9444 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9445 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9446 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9447 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9448 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9449 | try { |
| 9450 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9451 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9452 | } catch (SecurityException se) { |
| 9453 | enforceModifyPermission(); |
| 9454 | } |
| 9455 | } else { |
| 9456 | enforceModifyPermission(); |
| 9457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9458 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9459 | enforceTelephonyFeatureWithException(callingPackage, |
| 9460 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9461 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9462 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9463 | final long identity = Binder.clearCallingIdentity(); |
| 9464 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9465 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9466 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 9467 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
| 9468 | callingUid, callingPackage, null, null); |
| 9469 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9470 | Phone phone = getPhone(subId); |
| 9471 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9472 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9473 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9474 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9475 | phone.getDataSettingsManager().setDataEnabled( |
| 9476 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9477 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9478 | } |
| 9479 | } finally { |
| 9480 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9481 | } |
| 9482 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9483 | |
| 9484 | /** |
| 9485 | * Get Client request stats |
| 9486 | * @return List of Client Request Stats |
| 9487 | * @hide |
| 9488 | */ |
| 9489 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9490 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9491 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9492 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9493 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9494 | return null; |
| 9495 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9496 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9497 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9498 | final long identity = Binder.clearCallingIdentity(); |
| 9499 | try { |
| 9500 | if (phone != null) { |
| 9501 | return phone.getClientRequestStats(); |
| 9502 | } |
| 9503 | |
| 9504 | return null; |
| 9505 | } finally { |
| 9506 | Binder.restoreCallingIdentity(identity); |
| 9507 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9508 | } |
| 9509 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9510 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9511 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9512 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9513 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9514 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9515 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9516 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9517 | // commands that plumb through the RIL as root, like so: |
| 9518 | // $ adb root |
| 9519 | // $ adb shell cmd phone ... |
| 9520 | packageName = "root"; |
| 9521 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9522 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9523 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9524 | |
| 9525 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9526 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9527 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9528 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9529 | * @param state State of SIM (power down, power up, pass through) |
| 9530 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9531 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9532 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9533 | * |
| 9534 | **/ |
| 9535 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9536 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9537 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9538 | |
| 9539 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9540 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9541 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9542 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9543 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9544 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9545 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9546 | final long identity = Binder.clearCallingIdentity(); |
| 9547 | try { |
| 9548 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9549 | phone.setSimPowerState(state, null, workSource); |
| 9550 | } |
| 9551 | } finally { |
| 9552 | Binder.restoreCallingIdentity(identity); |
| 9553 | } |
| 9554 | } |
| 9555 | |
| 9556 | /** |
| 9557 | * Set SIM card power state. |
| 9558 | * |
| 9559 | * @param slotIndex SIM slot id. |
| 9560 | * @param state State of SIM (power down, power up, pass through) |
| 9561 | * @param callback callback to trigger after success or failure |
| 9562 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9563 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9564 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9565 | * |
| 9566 | **/ |
| 9567 | @Override |
| 9568 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9569 | IIntegerConsumer callback) { |
| 9570 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9571 | |
| 9572 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9573 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9574 | "setSimPowerStateForSlotWithCallback"); |
| 9575 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9576 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9577 | |
| 9578 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9579 | |
| 9580 | final long identity = Binder.clearCallingIdentity(); |
| 9581 | try { |
| 9582 | if (phone != null) { |
| 9583 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9584 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9585 | } |
| 9586 | } finally { |
| 9587 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9588 | } |
| 9589 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9590 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9591 | private boolean isUssdApiAllowed(int subId) { |
| 9592 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9593 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9594 | if (configManager == null) { |
| 9595 | return false; |
| 9596 | } |
| 9597 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9598 | if (pb == null) { |
| 9599 | return false; |
| 9600 | } |
| 9601 | return pb.getBoolean( |
| 9602 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9603 | } |
| 9604 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9605 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9606 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9607 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9608 | * @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] | 9609 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9610 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9611 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9612 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9613 | |
| 9614 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9615 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9616 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9617 | final long identity = Binder.clearCallingIdentity(); |
| 9618 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9619 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9622 | } |
| 9623 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9624 | |
| 9625 | /** |
| 9626 | * Get the current signal strength information for the given subscription. |
| 9627 | * Because this information is not updated when the device is in a low power state |
| 9628 | * it should not be relied-upon to be current. |
| 9629 | * @param subId Subscription index |
| 9630 | * @return the most recent cached signal strength info from the modem |
| 9631 | */ |
| 9632 | @Override |
| 9633 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9634 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9635 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9636 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9637 | final long identity = Binder.clearCallingIdentity(); |
| 9638 | try { |
| 9639 | Phone p = getPhone(subId); |
| 9640 | if (p == null) { |
| 9641 | return null; |
| 9642 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9643 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9644 | return p.getSignalStrength(); |
| 9645 | } finally { |
| 9646 | Binder.restoreCallingIdentity(identity); |
| 9647 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9648 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9649 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9650 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9651 | * Get the current modem radio state for the given slot. |
| 9652 | * @param slotIndex slot index. |
| 9653 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9654 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9655 | * @return the current radio power state from the modem |
| 9656 | */ |
| 9657 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9658 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9659 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9660 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9661 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9662 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9663 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9664 | } |
| 9665 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9666 | enforceTelephonyFeatureWithException(callingPackage, |
| 9667 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9668 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9669 | final long identity = Binder.clearCallingIdentity(); |
| 9670 | try { |
| 9671 | return phone.getRadioPowerState(); |
| 9672 | } finally { |
| 9673 | Binder.restoreCallingIdentity(identity); |
| 9674 | } |
| 9675 | } |
| 9676 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9677 | } |
| 9678 | |
| 9679 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9680 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9681 | * |
| 9682 | * <p>Requires one of the following permissions: |
| 9683 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9684 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9685 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9686 | * privileges. |
| 9687 | * |
| 9688 | * @param subId subscription id |
| 9689 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9690 | * {@code false}. |
| 9691 | */ |
| 9692 | @Override |
| 9693 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9694 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9695 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9696 | try { |
| 9697 | mApp.enforceCallingOrSelfPermission( |
| 9698 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9699 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9700 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9701 | mApp.enforceCallingOrSelfPermission( |
| 9702 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9703 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9704 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9705 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9706 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9707 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9708 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9709 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9710 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9711 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9712 | boolean isEnabled = false; |
| 9713 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9714 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9715 | Phone phone = getPhone(subId); |
| 9716 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9717 | } finally { |
| 9718 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9719 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9720 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9721 | } |
| 9722 | |
| 9723 | |
| 9724 | /** |
| 9725 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9726 | * |
| 9727 | * <p> Requires permission: |
| 9728 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9729 | * privileges. |
| 9730 | * |
| 9731 | * @param subId subscription id |
| 9732 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9733 | */ |
| 9734 | @Override |
| 9735 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9737 | mApp, subId, "setDataRoamingEnabled"); |
| 9738 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9739 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9740 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9741 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9742 | final long identity = Binder.clearCallingIdentity(); |
| 9743 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9744 | Phone phone = getPhone(subId); |
| 9745 | if (phone != null) { |
| 9746 | phone.setDataRoamingEnabled(isEnabled); |
| 9747 | } |
| 9748 | } finally { |
| 9749 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9750 | } |
| 9751 | } |
| 9752 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9753 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9754 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9755 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9756 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9757 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9758 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9759 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9760 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9761 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9762 | boolean isAllowed = true; |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9765 | Phone phone = getPhone(subId); |
| 9766 | if (phone != null) { |
| 9767 | isAllowed = phone.isCspPlmnEnabled(); |
| 9768 | } |
| 9769 | } finally { |
| 9770 | Binder.restoreCallingIdentity(identity); |
| 9771 | } |
| 9772 | return isAllowed; |
| 9773 | } |
| 9774 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9775 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9776 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9777 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9778 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9779 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9780 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9781 | if (phone == null) { |
| 9782 | return false; |
| 9783 | } |
| 9784 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9785 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9786 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9787 | } |
| 9788 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9789 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9790 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9791 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9792 | mApp.getSystemService(AppOpsManager.class) |
| 9793 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9794 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9795 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9796 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9797 | try { |
| 9798 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9799 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9800 | } catch (SecurityException e) { |
| 9801 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9802 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9803 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9804 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9805 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9806 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9807 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9808 | |
| 9809 | enforceTelephonyFeatureWithException(callingPackage, |
| 9810 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9811 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9812 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9813 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9814 | Binder.getCallingUid())) { |
| 9815 | isIccIdAccessRestricted = true; |
| 9816 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9817 | final long identity = Binder.clearCallingIdentity(); |
| 9818 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9819 | UiccController uiccController = UiccController.getInstance(); |
| 9820 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9821 | if (hasReadPermission) { |
| 9822 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9823 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9824 | |
| 9825 | // Remove private info if the caller doesn't have access |
| 9826 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9827 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9828 | //setting the value after compatibility check |
| 9829 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9830 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9831 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9832 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9833 | if (card == null) { |
| 9834 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9835 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9836 | continue; |
| 9837 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9838 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9839 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9840 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9841 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9842 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9843 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9844 | for (UiccPortInfo portInfo : portInfos) { |
| 9845 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9846 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9847 | if (port == null) { |
| 9848 | // assume no access if port is null |
| 9849 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9850 | continue; |
| 9851 | } |
| 9852 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9853 | uiccPortInfos.add(portInfo); |
| 9854 | } else { |
| 9855 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9856 | } |
| 9857 | } |
| 9858 | filteredInfos.add(new UiccCardInfo( |
| 9859 | cardInfo.isEuicc(), |
| 9860 | cardInfo.getCardId(), |
| 9861 | null, |
| 9862 | cardInfo.getPhysicalSlotIndex(), |
| 9863 | cardInfo.isRemovable(), |
| 9864 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9865 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9866 | } |
| 9867 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9868 | } finally { |
| 9869 | Binder.restoreCallingIdentity(identity); |
| 9870 | } |
| 9871 | } |
| 9872 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9873 | /** |
| 9874 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9875 | * generally private and require carrier privileges to view. |
| 9876 | * |
| 9877 | * @hide |
| 9878 | */ |
| 9879 | @NonNull |
| 9880 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9881 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9882 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9883 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9884 | } |
| 9885 | return new UiccCardInfo( |
| 9886 | cardInfo.isEuicc(), |
| 9887 | cardInfo.getCardId(), |
| 9888 | null, |
| 9889 | cardInfo.getPhysicalSlotIndex(), |
| 9890 | cardInfo.isRemovable(), |
| 9891 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9892 | portinfo |
| 9893 | ); |
| 9894 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9895 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9896 | /** |
| 9897 | * @hide |
| 9898 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9899 | * These values are generally private and require carrier privileges to view. |
| 9900 | */ |
| 9901 | @NonNull |
| 9902 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9903 | return new UiccPortInfo( |
| 9904 | UiccPortInfo.ICCID_REDACTED, |
| 9905 | portInfo.getPortIndex(), |
| 9906 | portInfo.getLogicalSlotIndex(), |
| 9907 | portInfo.isActive() |
| 9908 | ); |
| 9909 | } |
| 9910 | @Override |
| 9911 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9912 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9913 | mApp.getSystemService(AppOpsManager.class) |
| 9914 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9915 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9916 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9917 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9918 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9919 | // we are reading iccId which is PII data. |
| 9920 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9921 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9922 | enforceTelephonyFeatureWithException(callingPackage, |
| 9923 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9924 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9925 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9926 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9927 | Binder.getCallingUid())) { |
| 9928 | isLogicalSlotAccessRestricted = true; |
| 9929 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9930 | final long identity = Binder.clearCallingIdentity(); |
| 9931 | try { |
| 9932 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9933 | if (slots == null || slots.length == 0) { |
| 9934 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9935 | return null; |
| 9936 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9937 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9938 | for (int i = 0; i < slots.length; i++) { |
| 9939 | UiccSlot slot = slots[i]; |
| 9940 | if (slot == null) { |
| 9941 | continue; |
| 9942 | } |
| 9943 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9944 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9945 | UiccCard card = slot.getUiccCard(); |
| 9946 | if (card != null) { |
| 9947 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9948 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9949 | cardId = slot.getEid(); |
| 9950 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9951 | // If cardId is null, use iccId of default port as cardId. |
| 9952 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9953 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9954 | } |
| 9955 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9956 | if (cardId != null) { |
| 9957 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9958 | // if cardId is an EID, it's all digits so this is fine |
| 9959 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9960 | } |
| 9961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9962 | int cardState = 0; |
| 9963 | switch (slot.getCardState()) { |
| 9964 | case CARDSTATE_ABSENT: |
| 9965 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9966 | break; |
| 9967 | case CARDSTATE_PRESENT: |
| 9968 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9969 | break; |
| 9970 | case CARDSTATE_ERROR: |
| 9971 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9972 | break; |
| 9973 | case CARDSTATE_RESTRICTED: |
| 9974 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9975 | break; |
| 9976 | default: |
| 9977 | break; |
| 9978 | |
| 9979 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9980 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9981 | int[] portIndexes = slot.getPortList(); |
| 9982 | for (int portIdx : portIndexes) { |
| 9983 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9984 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9985 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9986 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9987 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9988 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9989 | slot.isEuicc(), |
| 9990 | cardId, |
| 9991 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9992 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9993 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9994 | //setting the value after compatibility check |
| 9995 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9996 | } |
| 9997 | return infos; |
| 9998 | } finally { |
| 9999 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10000 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10001 | } |
| 10002 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10003 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10004 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10005 | boolean hasReadPermission) { |
| 10006 | String iccId = slot.getIccId(portIndex); |
| 10007 | if (hasReadPermission) { // if has read permission |
| 10008 | return iccId; |
| 10009 | } else { |
| 10010 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10011 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10012 | // if no read permission, checking carrier privilege access |
| 10013 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10014 | return iccId; |
| 10015 | } |
| 10016 | } |
| 10017 | } |
| 10018 | // No read permission or carrier privilege access. |
| 10019 | return UiccPortInfo.ICCID_REDACTED; |
| 10020 | } |
| 10021 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10022 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10023 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10024 | public boolean switchSlots(int[] physicalSlots) { |
| 10025 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10026 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10027 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10028 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10029 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10030 | final long identity = Binder.clearCallingIdentity(); |
| 10031 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10032 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10033 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10034 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10035 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10036 | physicalSlots[i], i)); |
| 10037 | } |
| 10038 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10039 | } finally { |
| 10040 | Binder.restoreCallingIdentity(identity); |
| 10041 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10042 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10043 | |
| 10044 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10045 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10046 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10047 | enforceModifyPermission(); |
| 10048 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10049 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10050 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10051 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10052 | final long identity = Binder.clearCallingIdentity(); |
| 10053 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10054 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10055 | } finally { |
| 10056 | Binder.restoreCallingIdentity(identity); |
| 10057 | } |
| 10058 | } |
| 10059 | |
| 10060 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10061 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10062 | enforceTelephonyFeatureWithException(callingPackage, |
| 10063 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10064 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10065 | final long identity = Binder.clearCallingIdentity(); |
| 10066 | try { |
| 10067 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10068 | } finally { |
| 10069 | Binder.restoreCallingIdentity(identity); |
| 10070 | } |
| 10071 | } |
| 10072 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10073 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10074 | * A test API to reload the UICC profile. |
| 10075 | * |
| 10076 | * <p>Requires that the calling app has permission |
| 10077 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10078 | * @hide |
| 10079 | */ |
| 10080 | @Override |
| 10081 | public void refreshUiccProfile(int subId) { |
| 10082 | enforceModifyPermission(); |
| 10083 | |
| 10084 | final long identity = Binder.clearCallingIdentity(); |
| 10085 | try { |
| 10086 | Phone phone = getPhone(subId); |
| 10087 | if (phone == null) { |
| 10088 | return; |
| 10089 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10090 | UiccPort uiccPort = phone.getUiccPort(); |
| 10091 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10092 | return; |
| 10093 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10094 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10095 | if (uiccProfile == null) { |
| 10096 | return; |
| 10097 | } |
| 10098 | uiccProfile.refresh(); |
| 10099 | } finally { |
| 10100 | Binder.restoreCallingIdentity(identity); |
| 10101 | } |
| 10102 | } |
| 10103 | |
| 10104 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10105 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10106 | */ |
| 10107 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10108 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10109 | } |
| 10110 | |
| 10111 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10112 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10113 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10114 | */ |
| 10115 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10116 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10117 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10118 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10119 | return list.get(phoneId); |
| 10120 | } |
| 10121 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10122 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10123 | |
| 10124 | @Override |
| 10125 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10126 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10127 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10128 | |
| 10129 | final long identity = Binder.clearCallingIdentity(); |
| 10130 | try { |
| 10131 | final Phone phone = getPhone(subId); |
| 10132 | if (phone == null) { |
| 10133 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10134 | return; |
| 10135 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10136 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10137 | if (cpt != null) { |
| 10138 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10139 | } |
| 10140 | // 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] | 10141 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10142 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10143 | if (carrierPrivilegeRules == null) { |
| 10144 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10145 | } else { |
| 10146 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10147 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10148 | } finally { |
| 10149 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10150 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10151 | } |
| 10152 | |
| 10153 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10154 | public void setCarrierServicePackageOverride( |
| 10155 | int subId, String carrierServicePackage, String callingPackage) { |
| 10156 | TelephonyPermissions.enforceShellOnly( |
| 10157 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10158 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10159 | final long identity = Binder.clearCallingIdentity(); |
| 10160 | try { |
| 10161 | final Phone phone = getPhone(subId); |
| 10162 | if (phone == null || phone.getSubId() != subId) { |
| 10163 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10164 | throw new IllegalArgumentException("No phone for subid"); |
| 10165 | } |
| 10166 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10167 | if (cpt == null) { |
| 10168 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10169 | throw new IllegalStateException("No CPT for phone"); |
| 10170 | } |
| 10171 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10172 | } finally { |
| 10173 | Binder.restoreCallingIdentity(identity); |
| 10174 | } |
| 10175 | } |
| 10176 | |
| 10177 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10178 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10179 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10180 | |
| 10181 | final long identity = Binder.clearCallingIdentity(); |
| 10182 | try { |
| 10183 | final Phone phone = getPhone(subId); |
| 10184 | if (phone == null) { |
| 10185 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10186 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10187 | } |
| 10188 | return phone.getCarrierIdListVersion(); |
| 10189 | } finally { |
| 10190 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10191 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10192 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10193 | |
| 10194 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10195 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10196 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10197 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10198 | mApp, subId, callingPackage, callingFeatureId, |
| 10199 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10200 | return -1; |
| 10201 | } |
| 10202 | |
| 10203 | final long identity = Binder.clearCallingIdentity(); |
| 10204 | try { |
| 10205 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10206 | } finally { |
| 10207 | Binder.restoreCallingIdentity(identity); |
| 10208 | } |
| 10209 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10210 | |
| 10211 | @Override |
| 10212 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10213 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10214 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10215 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10216 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10217 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10218 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10219 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10220 | final long identity = Binder.clearCallingIdentity(); |
| 10221 | try { |
| 10222 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10223 | } finally { |
| 10224 | Binder.restoreCallingIdentity(identity); |
| 10225 | } |
| 10226 | } |
| 10227 | |
| 10228 | @Override |
| 10229 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10230 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10231 | mApp, subId, "setCdmaRoamingMode"); |
| 10232 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10233 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10234 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10235 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10236 | final long identity = Binder.clearCallingIdentity(); |
| 10237 | try { |
| 10238 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10239 | } finally { |
| 10240 | Binder.restoreCallingIdentity(identity); |
| 10241 | } |
| 10242 | } |
| 10243 | |
| 10244 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10245 | public int getCdmaSubscriptionMode(int subId) { |
| 10246 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10247 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10248 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10249 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10250 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10251 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10252 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10253 | final long identity = Binder.clearCallingIdentity(); |
| 10254 | try { |
| 10255 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10256 | } finally { |
| 10257 | Binder.restoreCallingIdentity(identity); |
| 10258 | } |
| 10259 | } |
| 10260 | |
| 10261 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10262 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10263 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10264 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10265 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10266 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10267 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10268 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10269 | final long identity = Binder.clearCallingIdentity(); |
| 10270 | try { |
| 10271 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10272 | } finally { |
| 10273 | Binder.restoreCallingIdentity(identity); |
| 10274 | } |
| 10275 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10276 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10277 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10278 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10279 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10280 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10281 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10282 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10283 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10284 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10285 | |
| 10286 | enforceTelephonyFeatureWithException(callingPackage, |
| 10287 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10288 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10289 | final long identity = Binder.clearCallingIdentity(); |
| 10290 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10291 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10292 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10293 | if (phone.getEmergencyNumberTracker() != null |
| 10294 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10295 | emergencyNumberListInternal.put( |
| 10296 | phone.getSubId(), |
| 10297 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10298 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10299 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10300 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10301 | } finally { |
| 10302 | Binder.restoreCallingIdentity(identity); |
| 10303 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10304 | } |
| 10305 | |
| 10306 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10307 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10308 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10309 | if (!exactMatch) { |
| 10310 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10311 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10312 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10313 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10314 | |
| 10315 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10316 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10317 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10318 | final long identity = Binder.clearCallingIdentity(); |
| 10319 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10320 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10321 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10322 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10323 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10324 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10325 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10326 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10327 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10328 | } |
| 10329 | return false; |
| 10330 | } finally { |
| 10331 | Binder.restoreCallingIdentity(identity); |
| 10332 | } |
| 10333 | } |
| 10334 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10335 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10336 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10337 | */ |
| 10338 | @Override |
| 10339 | public void startEmergencyCallbackMode() { |
| 10340 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10341 | "startEmergencyCallbackMode"); |
| 10342 | enforceModifyPermission(); |
| 10343 | final long identity = Binder.clearCallingIdentity(); |
| 10344 | try { |
| 10345 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10346 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10347 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10348 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10349 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10350 | gsmCdmaPhone.obtainMessage( |
| 10351 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10352 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10353 | } |
| 10354 | } |
| 10355 | } finally { |
| 10356 | Binder.restoreCallingIdentity(identity); |
| 10357 | } |
| 10358 | } |
| 10359 | |
| 10360 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10361 | * Update emergency number list for test mode. |
| 10362 | */ |
| 10363 | @Override |
| 10364 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10365 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10366 | "updateEmergencyNumberListTestMode"); |
| 10367 | |
| 10368 | final long identity = Binder.clearCallingIdentity(); |
| 10369 | try { |
| 10370 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10371 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10372 | if (tracker != null) { |
| 10373 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10374 | } |
| 10375 | } |
| 10376 | } finally { |
| 10377 | Binder.restoreCallingIdentity(identity); |
| 10378 | } |
| 10379 | } |
| 10380 | |
| 10381 | /** |
| 10382 | * Get the full emergency number list for test mode. |
| 10383 | */ |
| 10384 | @Override |
| 10385 | public List<String> getEmergencyNumberListTestMode() { |
| 10386 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10387 | "getEmergencyNumberListTestMode"); |
| 10388 | |
| 10389 | final long identity = Binder.clearCallingIdentity(); |
| 10390 | try { |
| 10391 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10392 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10393 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10394 | if (tracker != null) { |
| 10395 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10396 | emergencyNumbers.add(num.getNumber()); |
| 10397 | } |
| 10398 | } |
| 10399 | } |
| 10400 | return new ArrayList<>(emergencyNumbers); |
| 10401 | } finally { |
| 10402 | Binder.restoreCallingIdentity(identity); |
| 10403 | } |
| 10404 | } |
| 10405 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10406 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10407 | public int getEmergencyNumberDbVersion(int subId) { |
| 10408 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10409 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10410 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10411 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10412 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10413 | final long identity = Binder.clearCallingIdentity(); |
| 10414 | try { |
| 10415 | final Phone phone = getPhone(subId); |
| 10416 | if (phone == null) { |
| 10417 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10418 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10419 | } |
| 10420 | return phone.getEmergencyNumberDbVersion(); |
| 10421 | } finally { |
| 10422 | Binder.restoreCallingIdentity(identity); |
| 10423 | } |
| 10424 | } |
| 10425 | |
| 10426 | @Override |
| 10427 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10428 | enforceModifyPermission(); |
| 10429 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10430 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10431 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10432 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10433 | final long identity = Binder.clearCallingIdentity(); |
| 10434 | try { |
| 10435 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10436 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10437 | if (tracker != null) { |
| 10438 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10439 | } |
| 10440 | } |
| 10441 | } finally { |
| 10442 | Binder.restoreCallingIdentity(identity); |
| 10443 | } |
| 10444 | } |
| 10445 | |
| 10446 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10447 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10448 | enforceActiveEmergencySessionPermission(); |
| 10449 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10450 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10451 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10452 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10453 | final long identity = Binder.clearCallingIdentity(); |
| 10454 | try { |
| 10455 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10456 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10457 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10458 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10459 | } |
| 10460 | } |
| 10461 | } finally { |
| 10462 | Binder.restoreCallingIdentity(identity); |
| 10463 | } |
| 10464 | } |
| 10465 | |
| 10466 | @Override |
| 10467 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10468 | enforceActiveEmergencySessionPermission(); |
| 10469 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10470 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10471 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10472 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10473 | final long identity = Binder.clearCallingIdentity(); |
| 10474 | try { |
| 10475 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10476 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10477 | if (tracker != null) { |
| 10478 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10479 | } |
| 10480 | } |
| 10481 | } finally { |
| 10482 | Binder.restoreCallingIdentity(identity); |
| 10483 | } |
| 10484 | } |
| 10485 | |
| 10486 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10487 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10488 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10489 | Phone phone = getPhone(subId); |
| 10490 | if (phone == null) { |
| 10491 | return null; |
| 10492 | } |
| 10493 | final long identity = Binder.clearCallingIdentity(); |
| 10494 | try { |
| 10495 | UiccProfile profile = UiccController.getInstance() |
| 10496 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10497 | if (profile != null) { |
| 10498 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10499 | } |
| 10500 | } finally { |
| 10501 | Binder.restoreCallingIdentity(identity); |
| 10502 | } |
| 10503 | return null; |
| 10504 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10505 | |
| 10506 | /** |
| 10507 | * Enable or disable a modem stack. |
| 10508 | */ |
| 10509 | @Override |
| 10510 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10511 | enforceModifyPermission(); |
| 10512 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10513 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10514 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10515 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10516 | final long identity = Binder.clearCallingIdentity(); |
| 10517 | try { |
| 10518 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10519 | if (phone == null) { |
| 10520 | return false; |
| 10521 | } else { |
| 10522 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10523 | } |
| 10524 | } finally { |
| 10525 | Binder.restoreCallingIdentity(identity); |
| 10526 | } |
| 10527 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10528 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10529 | /** |
| 10530 | * Whether a modem stack is enabled or not. |
| 10531 | */ |
| 10532 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10533 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10534 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10535 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10536 | if (phone == null) return false; |
| 10537 | |
| 10538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10539 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10540 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10541 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10542 | } |
| 10543 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10544 | enforceTelephonyFeatureWithException(callingPackage, |
| 10545 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10546 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10547 | final long identity = Binder.clearCallingIdentity(); |
| 10548 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10549 | try { |
| 10550 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10551 | } catch (NoSuchElementException ex) { |
| 10552 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10553 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10554 | } finally { |
| 10555 | Binder.restoreCallingIdentity(identity); |
| 10556 | } |
| 10557 | } |
| 10558 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10559 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10560 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10561 | enforceModifyPermission(); |
| 10562 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10563 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10564 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10565 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10566 | final long identity = Binder.clearCallingIdentity(); |
| 10567 | try { |
| 10568 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10569 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10570 | .commit(); |
| 10571 | } finally { |
| 10572 | Binder.restoreCallingIdentity(identity); |
| 10573 | } |
| 10574 | } |
| 10575 | |
| 10576 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10577 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10578 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10579 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10580 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10581 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10582 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10583 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10584 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10585 | enforceTelephonyFeatureWithException(callingPackage, |
| 10586 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10587 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10588 | final long identity = Binder.clearCallingIdentity(); |
| 10589 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10590 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10591 | } finally { |
| 10592 | Binder.restoreCallingIdentity(identity); |
| 10593 | } |
| 10594 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10595 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10596 | @TelephonyManager.IsMultiSimSupportedResult |
| 10597 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10598 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10599 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10600 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10601 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10602 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10603 | } |
| 10604 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10605 | // supported by the modem, indicate that it is restricted. |
| 10606 | PhoneCapability staticCapability = |
| 10607 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10608 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10609 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10610 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10611 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10612 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10613 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10614 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10615 | } |
| 10616 | // Check if support of multiple SIMs is restricted by carrier |
| 10617 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10618 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10619 | } |
| 10620 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10621 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10622 | } |
| 10623 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10624 | /** |
| 10625 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10626 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10627 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10628 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10629 | * @param numOfSims number of active sims we want to switch to |
| 10630 | */ |
| 10631 | @Override |
| 10632 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10633 | if (numOfSims == 1) { |
| 10634 | enforceModifyPermission(); |
| 10635 | } else { |
| 10636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10637 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10638 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10639 | |
| 10640 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10641 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10642 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10643 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10644 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10645 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10646 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10647 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10648 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10649 | return; |
| 10650 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10651 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10652 | } finally { |
| 10653 | Binder.restoreCallingIdentity(identity); |
| 10654 | } |
| 10655 | } |
| 10656 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10657 | @Override |
| 10658 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10659 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10660 | |
| 10661 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10662 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10663 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10664 | Phone phone = getPhone(subId); |
| 10665 | if (phone == null) { |
| 10666 | return false; |
| 10667 | } |
| 10668 | final long identity = Binder.clearCallingIdentity(); |
| 10669 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10670 | UiccPort uiccPort = phone.getUiccPort(); |
| 10671 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10672 | return false; |
| 10673 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10674 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10675 | if (uiccProfile == null) { |
| 10676 | return false; |
| 10677 | } |
| 10678 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10679 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10680 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10681 | } |
| 10682 | return false; |
| 10683 | } finally { |
| 10684 | Binder.restoreCallingIdentity(identity); |
| 10685 | } |
| 10686 | } |
| 10687 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10688 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10689 | * Get whether making changes to modem configurations will trigger reboot. |
| 10690 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10691 | */ |
| 10692 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10693 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10694 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10695 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10696 | mApp, subId, callingPackage, callingFeatureId, |
| 10697 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10698 | return false; |
| 10699 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10700 | |
| 10701 | enforceTelephonyFeatureWithException(callingPackage, |
| 10702 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10703 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10704 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10705 | final long identity = Binder.clearCallingIdentity(); |
| 10706 | try { |
| 10707 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10708 | } finally { |
| 10709 | Binder.restoreCallingIdentity(identity); |
| 10710 | } |
| 10711 | } |
| 10712 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10713 | private void updateModemStateMetrics() { |
| 10714 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10715 | // TODO: check the state for each modem if the api is ready. |
| 10716 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10717 | } |
| 10718 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10719 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10720 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10721 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10722 | // Verify that the callingPackage belongs to the calling UID |
| 10723 | mApp.getSystemService(AppOpsManager.class) |
| 10724 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10725 | |
| 10726 | enforceTelephonyFeatureWithException(callingPackage, |
| 10727 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10728 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10729 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10730 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10731 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10732 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10733 | if (slotInfos != null) { |
| 10734 | for (int i = 0; i < slotInfos.length; i++) { |
| 10735 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10736 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10737 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10738 | portInfo.getLogicalSlotIndex())); |
| 10739 | } |
| 10740 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10741 | } |
| 10742 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10743 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10744 | } finally { |
| 10745 | Binder.restoreCallingIdentity(identity); |
| 10746 | } |
| 10747 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10748 | |
| 10749 | /** |
| 10750 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10751 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10752 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10753 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10754 | @Override |
| 10755 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10756 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10757 | } |
| 10758 | |
| 10759 | /** |
| 10760 | * Get the HAL Version of a specific service |
| 10761 | */ |
| 10762 | @Override |
| 10763 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10764 | Phone phone = getDefaultPhone(); |
| 10765 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10766 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10767 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10768 | return hv.major * 100 + hv.minor; |
| 10769 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10770 | |
| 10771 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10772 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10773 | * |
| 10774 | * @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] | 10775 | */ |
| 10776 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10777 | public @Nullable String getCurrentPackageName() { |
| 10778 | PackageManager pm = mApp.getPackageManager(); |
| 10779 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10780 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10781 | } |
| 10782 | |
| 10783 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10784 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10785 | * corresponding network requests on a subId. |
| 10786 | * |
| 10787 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10788 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10789 | * 2) APN is un-metered for this subscription, or |
| 10790 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10791 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10792 | * |
| 10793 | * @return whether data is allowed for a apn type. |
| 10794 | * |
| 10795 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10796 | */ |
| 10797 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10798 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10799 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10800 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10801 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10802 | enforceTelephonyFeatureWithException(callingPackage, |
| 10803 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10804 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10805 | // Now that all security checks passes, perform the operation as ourselves. |
| 10806 | final long identity = Binder.clearCallingIdentity(); |
| 10807 | try { |
| 10808 | Phone phone = getPhone(subId); |
| 10809 | if (phone == null) return false; |
| 10810 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10811 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10812 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10813 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10814 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10815 | phone.getServiceState().getDataRoaming()); |
| 10816 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10817 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10818 | } finally { |
| 10819 | Binder.restoreCallingIdentity(identity); |
| 10820 | } |
| 10821 | } |
| 10822 | |
| 10823 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10824 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10825 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10826 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10827 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10828 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10829 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10830 | // Now that all security checks passes, perform the operation as ourselves. |
| 10831 | final long identity = Binder.clearCallingIdentity(); |
| 10832 | try { |
| 10833 | Phone phone = getPhone(subId); |
| 10834 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10835 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10836 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10837 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10838 | } finally { |
| 10839 | Binder.restoreCallingIdentity(identity); |
| 10840 | } |
| 10841 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10842 | |
| 10843 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10844 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10845 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10846 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10847 | |
| 10848 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10849 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10850 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10851 | long token = Binder.clearCallingIdentity(); |
| 10852 | try { |
| 10853 | Phone phone = getPhone(subscriptionId); |
| 10854 | if (phone == null) { |
| 10855 | try { |
| 10856 | if (resultCallback != null) { |
| 10857 | resultCallback.accept(false); |
| 10858 | } |
| 10859 | } catch (RemoteException e) { |
| 10860 | // ignore |
| 10861 | } |
| 10862 | return; |
| 10863 | } |
| 10864 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10865 | Pair.create(specifiers, (x) -> { |
| 10866 | try { |
| 10867 | if (resultCallback != null) { |
| 10868 | resultCallback.accept(x); |
| 10869 | } |
| 10870 | } catch (RemoteException e) { |
| 10871 | // ignore |
| 10872 | } |
| 10873 | }); |
| 10874 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10875 | } finally { |
| 10876 | Binder.restoreCallingIdentity(token); |
| 10877 | } |
| 10878 | } |
| 10879 | |
| 10880 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10881 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10882 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10883 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10884 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10885 | |
| 10886 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10887 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10888 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10889 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10890 | final long identity = Binder.clearCallingIdentity(); |
| 10891 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10892 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10893 | if (result instanceof IllegalStateException) { |
| 10894 | throw (IllegalStateException) result; |
| 10895 | } |
| 10896 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10897 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10898 | return specifiers; |
| 10899 | } finally { |
| 10900 | Binder.restoreCallingIdentity(identity); |
| 10901 | } |
| 10902 | } |
| 10903 | |
| 10904 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10905 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10906 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10907 | |
| 10908 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10909 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10910 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10911 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10912 | } |
| 10913 | |
| 10914 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10915 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10916 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10917 | if (callingPackage == null) { |
| 10918 | callingPackage = getCurrentPackageName(); |
| 10919 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10920 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10921 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10922 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10923 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10924 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10925 | } |
| 10926 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10927 | Intent intent = new Intent(); |
| 10928 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10929 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10930 | // Bring up choose default SMS subscription dialog right now |
| 10931 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10932 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10933 | mApp.startActivity(intent); |
| 10934 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10935 | |
| 10936 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10937 | public void showSwitchToManagedProfileDialog() { |
| 10938 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10939 | try { |
| 10940 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10941 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10942 | // for work telephony. |
| 10943 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10944 | intent.setData(Uri.parse("smsto:")); |
| 10945 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10946 | mApp.startActivity(intent); |
| 10947 | } catch (ActivityNotFoundException e) { |
| 10948 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10949 | Intent intent = new Intent(); |
| 10950 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10951 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10952 | mApp.startActivity(intent); |
| 10953 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10954 | } |
| 10955 | |
| 10956 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10957 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10958 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10959 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 10960 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10961 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10962 | final long identity = Binder.clearCallingIdentity(); |
| 10963 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10964 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10965 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10966 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10967 | return carrierUAProfUrl; |
| 10968 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10969 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10970 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10971 | } finally { |
| 10972 | Binder.restoreCallingIdentity(identity); |
| 10973 | } |
| 10974 | } |
| 10975 | |
| 10976 | @Override |
| 10977 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10978 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10979 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 10980 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10981 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10982 | final long identity = Binder.clearCallingIdentity(); |
| 10983 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10984 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10985 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10986 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10987 | return carrierUserAgent; |
| 10988 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10989 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10990 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10991 | } finally { |
| 10992 | Binder.restoreCallingIdentity(identity); |
| 10993 | } |
| 10994 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10995 | |
| 10996 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10997 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10998 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10999 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11000 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11001 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11002 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11003 | final long identity = Binder.clearCallingIdentity(); |
| 11004 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11005 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11006 | if (phone == null) return false; |
| 11007 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11008 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11009 | } finally { |
| 11010 | Binder.restoreCallingIdentity(identity); |
| 11011 | } |
| 11012 | } |
| 11013 | |
| 11014 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11015 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11016 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11017 | enforceModifyPermission(); |
| 11018 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11019 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11020 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11021 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11022 | final long identity = Binder.clearCallingIdentity(); |
| 11023 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11024 | Phone phone = getPhone(subscriptionId); |
| 11025 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11026 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11027 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11028 | } finally { |
| 11029 | Binder.restoreCallingIdentity(identity); |
| 11030 | } |
| 11031 | } |
| 11032 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11033 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11034 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11035 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11036 | * otherwise. |
| 11037 | */ |
| 11038 | @Override |
| 11039 | public void setCepEnabled(boolean isCepEnabled) { |
| 11040 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11041 | |
| 11042 | final long identity = Binder.clearCallingIdentity(); |
| 11043 | try { |
| 11044 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11045 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11046 | Phone defaultPhone = phone.getImsPhone(); |
| 11047 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11048 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11049 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11050 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11051 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11052 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11053 | + imsPhone.getMsisdn()); |
| 11054 | } |
| 11055 | } |
| 11056 | } finally { |
| 11057 | Binder.restoreCallingIdentity(identity); |
| 11058 | } |
| 11059 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11060 | |
| 11061 | /** |
| 11062 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11063 | * |
| 11064 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11065 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11066 | * before being read. |
| 11067 | */ |
| 11068 | @Override |
| 11069 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11070 | isCompressed) { |
| 11071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11072 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11073 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11074 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11075 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11076 | |
| 11077 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11078 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11079 | Binder.getCallingUserHandle())) { |
| 11080 | if (!isImsAvailableOnDevice()) { |
| 11081 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11082 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11083 | throw new IllegalStateException("IMS not available on device."); |
| 11084 | } |
| 11085 | } else { |
| 11086 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11087 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11088 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11089 | } |
| 11090 | |
| 11091 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11092 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11093 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11094 | } finally { |
| 11095 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11096 | } |
| 11097 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11098 | |
| 11099 | @Override |
| 11100 | public boolean isIccLockEnabled(int subId) { |
| 11101 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11102 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11103 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11104 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11105 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11106 | // Now that all security checks passes, perform the operation as ourselves. |
| 11107 | final long identity = Binder.clearCallingIdentity(); |
| 11108 | try { |
| 11109 | Phone phone = getPhone(subId); |
| 11110 | if (phone != null && phone.getIccCard() != null) { |
| 11111 | return phone.getIccCard().getIccLockEnabled(); |
| 11112 | } else { |
| 11113 | return false; |
| 11114 | } |
| 11115 | } finally { |
| 11116 | Binder.restoreCallingIdentity(identity); |
| 11117 | } |
| 11118 | } |
| 11119 | |
| 11120 | /** |
| 11121 | * Set the ICC pin lock enabled or disabled. |
| 11122 | * |
| 11123 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11124 | * three cases: |
| 11125 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11126 | * successfully. |
| 11127 | * - Positive number and zero for remaining password attempts. |
| 11128 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11129 | * |
| 11130 | */ |
| 11131 | @Override |
| 11132 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11133 | enforceModifyPermission(); |
| 11134 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11135 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11136 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11137 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11138 | Phone phone = getPhone(subId); |
| 11139 | if (phone == null) { |
| 11140 | return 0; |
| 11141 | } |
| 11142 | // Now that all security checks passes, perform the operation as ourselves. |
| 11143 | final long identity = Binder.clearCallingIdentity(); |
| 11144 | try { |
| 11145 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11146 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11147 | return attemptsRemaining; |
| 11148 | |
| 11149 | } catch (Exception e) { |
| 11150 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11151 | } finally { |
| 11152 | Binder.restoreCallingIdentity(identity); |
| 11153 | } |
| 11154 | return 0; |
| 11155 | } |
| 11156 | |
| 11157 | /** |
| 11158 | * Change the ICC password used in ICC pin lock. |
| 11159 | * |
| 11160 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11161 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11162 | * - Positive number and zero for remaining password attempts. |
| 11163 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11164 | * |
| 11165 | */ |
| 11166 | @Override |
| 11167 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11168 | enforceModifyPermission(); |
| 11169 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11170 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11171 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11172 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11173 | Phone phone = getPhone(subId); |
| 11174 | if (phone == null) { |
| 11175 | return 0; |
| 11176 | } |
| 11177 | // Now that all security checks passes, perform the operation as ourselves. |
| 11178 | final long identity = Binder.clearCallingIdentity(); |
| 11179 | try { |
| 11180 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11181 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11182 | return attemptsRemaining; |
| 11183 | |
| 11184 | } catch (Exception e) { |
| 11185 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11186 | } finally { |
| 11187 | Binder.restoreCallingIdentity(identity); |
| 11188 | } |
| 11189 | return 0; |
| 11190 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11191 | |
| 11192 | /** |
| 11193 | * Request for receiving user activity notification |
| 11194 | */ |
| 11195 | @Override |
| 11196 | public void requestUserActivityNotification() { |
| 11197 | if (!mNotifyUserActivity.get() |
| 11198 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11199 | mNotifyUserActivity.set(true); |
| 11200 | } |
| 11201 | } |
| 11202 | |
| 11203 | /** |
| 11204 | * Called when userActivity is signalled in the power manager. |
| 11205 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11206 | */ |
| 11207 | @Override |
| 11208 | public void userActivity() { |
| 11209 | // *************************************** |
| 11210 | // * Inherited from PhoneWindowManager * |
| 11211 | // *************************************** |
| 11212 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11213 | // WITH ITS LOCKS HELD. |
| 11214 | // |
| 11215 | // This code must be VERY careful about the locks |
| 11216 | // it acquires. |
| 11217 | // In fact, the current code acquires way too many, |
| 11218 | // and probably has lurking deadlocks. |
| 11219 | |
| 11220 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11221 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11222 | } |
| 11223 | |
| 11224 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11225 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11226 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11227 | } |
| 11228 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11229 | |
| 11230 | @Override |
| 11231 | public boolean canConnectTo5GInDsdsMode() { |
| 11232 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11233 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11234 | |
| 11235 | @Override |
| 11236 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11237 | String callingFeatureId) { |
| 11238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11239 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11240 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11241 | } |
| 11242 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11243 | enforceTelephonyFeatureWithException(callingPackage, |
| 11244 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11245 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11246 | Phone phone = getPhone(subId); |
| 11247 | if (phone == null) { |
| 11248 | throw new RuntimeException("phone is not available"); |
| 11249 | } |
| 11250 | // Now that all security checks passes, perform the operation as ourselves. |
| 11251 | final long identity = Binder.clearCallingIdentity(); |
| 11252 | try { |
| 11253 | return phone.getEquivalentHomePlmns(); |
| 11254 | } finally { |
| 11255 | Binder.restoreCallingIdentity(identity); |
| 11256 | } |
| 11257 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11258 | |
| 11259 | @Override |
| 11260 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11261 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11262 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11263 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11264 | "isRadioInterfaceCapabilitySupported"); |
| 11265 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11266 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11267 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11268 | if (radioInterfaceCapabilities == null) { |
| 11269 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11270 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11271 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11272 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11273 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11274 | @Override |
| 11275 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11276 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11277 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11278 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11279 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11280 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11281 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11282 | |
| 11283 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11284 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11285 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11286 | if (DBG) { |
| 11287 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11288 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11289 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11290 | } |
| 11291 | |
| 11292 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11293 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11294 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11295 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11296 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11297 | if (callback != null) { |
| 11298 | try { |
| 11299 | callback.onAuthenticationFailure( |
| 11300 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11301 | } catch (RemoteException exception) { |
| 11302 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11303 | } |
| 11304 | return; |
| 11305 | } |
| 11306 | } |
| 11307 | |
| 11308 | final long token = Binder.clearCallingIdentity(); |
| 11309 | try { |
| 11310 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11311 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11312 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11313 | } finally { |
| 11314 | Binder.restoreCallingIdentity(token); |
| 11315 | } |
| 11316 | } |
| 11317 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11318 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11319 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11320 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11321 | * requested radio power state will actually be set. See {@link |
| 11322 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11323 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11324 | * @param enable {@code true} if trying to turn radio on. |
| 11325 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11326 | * false}. |
| 11327 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11328 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11329 | boolean isPhoneAvailable = false; |
| 11330 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11331 | Phone phone = PhoneFactory.getPhone(i); |
| 11332 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11333 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11334 | isPhoneAvailable = true; |
| 11335 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11336 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11337 | |
| 11338 | // return true if successfully informed the phone object about the thermal radio power |
| 11339 | // request. |
| 11340 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11341 | } |
| 11342 | |
| 11343 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11344 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11345 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11346 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11347 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11348 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11349 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11350 | } |
| 11351 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11352 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11353 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11354 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11355 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11356 | } |
| 11357 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11358 | setDataEnabledForReason( |
| 11359 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11360 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11361 | if (isDataThrottlingSupported) { |
| 11362 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11363 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11364 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11365 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11366 | } else if (thermalMitigationResult |
| 11367 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11368 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11369 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11370 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11371 | } |
| 11372 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11373 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11374 | |
| 11375 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11376 | } |
| 11377 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11378 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11379 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11380 | for (String pckg : context.getResources() |
| 11381 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11382 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11383 | } |
| 11384 | } |
| 11385 | |
| 11386 | return sThermalMitigationAllowlistedPackages; |
| 11387 | } |
| 11388 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11389 | private boolean isAnyPhoneInEmergencyState() { |
| 11390 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11391 | if (tm.isInEmergencyCall()) { |
| 11392 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11393 | return true; |
| 11394 | } |
| 11395 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11396 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11397 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11398 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11399 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11400 | return true; |
| 11401 | } |
| 11402 | } |
| 11403 | |
| 11404 | return false; |
| 11405 | } |
| 11406 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11407 | /** |
| 11408 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11409 | * @param packageName name of package to be allowlisted |
| 11410 | * @param context |
| 11411 | */ |
| 11412 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11413 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11414 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11415 | } |
| 11416 | |
| 11417 | /** |
| 11418 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11419 | * @param packageName name of package to remove from allowlist |
| 11420 | * @param context |
| 11421 | */ |
| 11422 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11423 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11424 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11425 | } |
| 11426 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11427 | /** |
| 11428 | * Thermal mitigation request to control functionalities at modem. |
| 11429 | * |
| 11430 | * @param subId the id of the subscription. |
| 11431 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11432 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11433 | * |
| 11434 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11435 | */ |
| 11436 | @Override |
| 11437 | @ThermalMitigationResult |
| 11438 | public int sendThermalMitigationRequest( |
| 11439 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11440 | ThermalMitigationRequest thermalMitigationRequest, |
| 11441 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11442 | enforceModifyPermission(); |
| 11443 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11444 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11445 | |
| 11446 | enforceTelephonyFeatureWithException(callingPackage, |
| 11447 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11448 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11449 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11450 | .contains(callingPackage)) { |
| 11451 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11452 | + "calling package: " + callingPackage); |
| 11453 | } |
| 11454 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11455 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11456 | final long identity = Binder.clearCallingIdentity(); |
| 11457 | |
| 11458 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11459 | try { |
| 11460 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11461 | switch (thermalMitigationAction) { |
| 11462 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11463 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11464 | handleDataThrottlingRequest(subId, |
| 11465 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11466 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11467 | break; |
| 11468 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11469 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11470 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11471 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11472 | } |
| 11473 | |
| 11474 | // Ensure that radio is on. If not able to power on due to phone being |
| 11475 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11476 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11477 | thermalMitigationResult = |
| 11478 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11479 | break; |
| 11480 | } |
| 11481 | |
| 11482 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11483 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11484 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11485 | break; |
| 11486 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11487 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11488 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11489 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11490 | } |
| 11491 | |
| 11492 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11493 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11494 | Phone phone = getPhone(subId); |
| 11495 | if (phone == null) { |
| 11496 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11497 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11498 | break; |
| 11499 | } |
| 11500 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11501 | TelephonyConnectionService service = |
| 11502 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11503 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11504 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11505 | thermalMitigationResult = |
| 11506 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11507 | break; |
| 11508 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11509 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11510 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11511 | break; |
| 11512 | } |
| 11513 | } else { |
| 11514 | thermalMitigationResult = |
| 11515 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11516 | break; |
| 11517 | } |
| 11518 | |
| 11519 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11520 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11521 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11522 | thermalMitigationResult = |
| 11523 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11524 | break; |
| 11525 | } |
| 11526 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11527 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11528 | break; |
| 11529 | default: |
| 11530 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11531 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11532 | } |
| 11533 | } catch (IllegalArgumentException e) { |
| 11534 | throw e; |
| 11535 | } catch (Exception e) { |
| 11536 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11537 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11538 | } finally { |
| 11539 | Binder.restoreCallingIdentity(identity); |
| 11540 | } |
| 11541 | |
| 11542 | if (DBG) { |
| 11543 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11544 | + thermalMitigationResult); |
| 11545 | } |
| 11546 | |
| 11547 | return thermalMitigationResult; |
| 11548 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11549 | |
| 11550 | /** |
| 11551 | * Set the GbaService Package Name that Telephony will bind to. |
| 11552 | * |
| 11553 | * @param subId The sim that the GbaService is associated with. |
| 11554 | * @param packageName The name of the package to be replaced with. |
| 11555 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11556 | */ |
| 11557 | @Override |
| 11558 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11559 | enforceModifyPermission(); |
| 11560 | |
| 11561 | final long identity = Binder.clearCallingIdentity(); |
| 11562 | try { |
| 11563 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11564 | } finally { |
| 11565 | Binder.restoreCallingIdentity(identity); |
| 11566 | } |
| 11567 | } |
| 11568 | |
| 11569 | /** |
| 11570 | * Return the package name of the currently bound GbaService. |
| 11571 | * |
| 11572 | * @param subId The sim that the GbaService is associated with. |
| 11573 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11574 | */ |
| 11575 | @Override |
| 11576 | public String getBoundGbaService(int subId) { |
| 11577 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11578 | |
| 11579 | final long identity = Binder.clearCallingIdentity(); |
| 11580 | try { |
| 11581 | return getGbaManager(subId).getServicePackage(); |
| 11582 | } finally { |
| 11583 | Binder.restoreCallingIdentity(identity); |
| 11584 | } |
| 11585 | } |
| 11586 | |
| 11587 | /** |
| 11588 | * Set the release time for telephony to unbind GbaService. |
| 11589 | * |
| 11590 | * @param subId The sim that the GbaService is associated with. |
| 11591 | * @param interval The release time to unbind GbaService by millisecond. |
| 11592 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11593 | */ |
| 11594 | @Override |
| 11595 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11596 | enforceModifyPermission(); |
| 11597 | |
| 11598 | final long identity = Binder.clearCallingIdentity(); |
| 11599 | try { |
| 11600 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11601 | } finally { |
| 11602 | Binder.restoreCallingIdentity(identity); |
| 11603 | } |
| 11604 | } |
| 11605 | |
| 11606 | /** |
| 11607 | * Return the release time for telephony to unbind GbaService. |
| 11608 | * |
| 11609 | * @param subId The sim that the GbaService is associated with. |
| 11610 | * @return The release time to unbind GbaService by millisecond. |
| 11611 | */ |
| 11612 | @Override |
| 11613 | public int getGbaReleaseTime(int subId) { |
| 11614 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11615 | |
| 11616 | final long identity = Binder.clearCallingIdentity(); |
| 11617 | try { |
| 11618 | return getGbaManager(subId).getReleaseTime(); |
| 11619 | } finally { |
| 11620 | Binder.restoreCallingIdentity(identity); |
| 11621 | } |
| 11622 | } |
| 11623 | |
| 11624 | private GbaManager getGbaManager(int subId) { |
| 11625 | GbaManager instance = GbaManager.getInstance(subId); |
| 11626 | if (instance == null) { |
| 11627 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11628 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11629 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11630 | } |
| 11631 | return instance; |
| 11632 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11633 | |
| 11634 | /** |
| 11635 | * indicate whether the device and the carrier can support |
| 11636 | * RCS VoLTE single registration. |
| 11637 | */ |
| 11638 | @Override |
| 11639 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11640 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11641 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11642 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11643 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11644 | |
| 11645 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11646 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11647 | } |
| 11648 | |
| 11649 | final long identity = Binder.clearCallingIdentity(); |
| 11650 | try { |
| 11651 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11652 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11653 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11654 | if (isCapable != null) { |
| 11655 | return isCapable; |
| 11656 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11657 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11658 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11659 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11660 | } finally { |
| 11661 | Binder.restoreCallingIdentity(identity); |
| 11662 | } |
| 11663 | } |
| 11664 | |
| 11665 | /** |
| 11666 | * Register RCS provisioning callback. |
| 11667 | */ |
| 11668 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11669 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11670 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11671 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11672 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11673 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11674 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11675 | |
| 11676 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11677 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11678 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11679 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11680 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11681 | Binder.getCallingUserHandle())) { |
| 11682 | if (!isImsAvailableOnDevice()) { |
| 11683 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11684 | "IMS not available on device."); |
| 11685 | } |
| 11686 | } else { |
| 11687 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11688 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11689 | } |
| 11690 | |
| 11691 | final long identity = Binder.clearCallingIdentity(); |
| 11692 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11693 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11694 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11695 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11696 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11697 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11698 | } finally { |
| 11699 | Binder.restoreCallingIdentity(identity); |
| 11700 | } |
| 11701 | } |
| 11702 | |
| 11703 | /** |
| 11704 | * Unregister RCS provisioning callback. |
| 11705 | */ |
| 11706 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11707 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11708 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11709 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11710 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11711 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11712 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11713 | |
| 11714 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11715 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11716 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11717 | |
| 11718 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11719 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11720 | Binder.getCallingUserHandle())) { |
| 11721 | if (!isImsAvailableOnDevice()) { |
| 11722 | // operation failed silently |
| 11723 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11724 | return; |
| 11725 | } |
| 11726 | } else { |
| 11727 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11728 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11729 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11730 | } |
| 11731 | |
| 11732 | final long identity = Binder.clearCallingIdentity(); |
| 11733 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11734 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11735 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11736 | } finally { |
| 11737 | Binder.restoreCallingIdentity(identity); |
| 11738 | } |
| 11739 | } |
| 11740 | |
| 11741 | /** |
| 11742 | * trigger RCS reconfiguration. |
| 11743 | */ |
| 11744 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11745 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11746 | "triggerRcsReconfiguration", |
| 11747 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11748 | |
| 11749 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11750 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11751 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11752 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11753 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11754 | Binder.getCallingUserHandle())) { |
| 11755 | if (!isImsAvailableOnDevice()) { |
| 11756 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11757 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11758 | throw new IllegalStateException("IMS not available on device."); |
| 11759 | } |
| 11760 | } else { |
| 11761 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11762 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11763 | } |
| 11764 | |
| 11765 | final long identity = Binder.clearCallingIdentity(); |
| 11766 | try { |
| 11767 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11768 | } finally { |
| 11769 | Binder.restoreCallingIdentity(identity); |
| 11770 | } |
| 11771 | } |
| 11772 | |
| 11773 | /** |
| 11774 | * Provide the client configuration parameters of the RCS application. |
| 11775 | */ |
| 11776 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11777 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11778 | "setRcsClientConfiguration", |
| 11779 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11780 | |
| 11781 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11782 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11783 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11784 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11785 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11786 | Binder.getCallingUserHandle())) { |
| 11787 | if (!isImsAvailableOnDevice()) { |
| 11788 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11789 | "IMS not available on device."); |
| 11790 | } |
| 11791 | } else { |
| 11792 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11793 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11794 | } |
| 11795 | |
| 11796 | final long identity = Binder.clearCallingIdentity(); |
| 11797 | |
| 11798 | try { |
| 11799 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11800 | if (configBinder == null) { |
| 11801 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11802 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11803 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11804 | } else { |
| 11805 | configBinder.setRcsClientConfiguration(rcc); |
| 11806 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11807 | |
| 11808 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11809 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11810 | } catch (RemoteException e) { |
| 11811 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11812 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11813 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11814 | } finally { |
| 11815 | Binder.restoreCallingIdentity(identity); |
| 11816 | } |
| 11817 | } |
| 11818 | |
| 11819 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11820 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11821 | */ |
| 11822 | @Override |
| 11823 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11824 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11825 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11826 | |
| 11827 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11828 | } |
| 11829 | |
| 11830 | /** |
| 11831 | * Gets the test mode for RCS VoLTE single registration. |
| 11832 | */ |
| 11833 | @Override |
| 11834 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11835 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11836 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11837 | |
| 11838 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11839 | } |
| 11840 | |
| 11841 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11842 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11843 | */ |
| 11844 | @Override |
| 11845 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11846 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11847 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11848 | enforceModifyPermission(); |
| 11849 | |
| 11850 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11851 | : Boolean.parseBoolean(enabledStr); |
| 11852 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11853 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11854 | } |
| 11855 | |
| 11856 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11857 | * Sends a device to device communication message. Only usable via shell. |
| 11858 | * @param message message to send. |
| 11859 | * @param value message value. |
| 11860 | */ |
| 11861 | @Override |
| 11862 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11863 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11864 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11865 | enforceModifyPermission(); |
| 11866 | |
| 11867 | final long identity = Binder.clearCallingIdentity(); |
| 11868 | try { |
| 11869 | TelephonyConnectionService service = |
| 11870 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11871 | if (service == null) { |
| 11872 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11873 | return; |
| 11874 | } |
| 11875 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11876 | } finally { |
| 11877 | Binder.restoreCallingIdentity(identity); |
| 11878 | } |
| 11879 | } |
| 11880 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11881 | /** |
| 11882 | * Sets the specified device to device transport active. |
| 11883 | * @param transport The transport to set active. |
| 11884 | */ |
| 11885 | @Override |
| 11886 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11887 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11888 | "setActiveDeviceToDeviceTransport"); |
| 11889 | enforceModifyPermission(); |
| 11890 | |
| 11891 | final long identity = Binder.clearCallingIdentity(); |
| 11892 | try { |
| 11893 | TelephonyConnectionService service = |
| 11894 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11895 | if (service == null) { |
| 11896 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11897 | return; |
| 11898 | } |
| 11899 | service.setActiveDeviceToDeviceTransport(transport); |
| 11900 | } finally { |
| 11901 | Binder.restoreCallingIdentity(identity); |
| 11902 | } |
| 11903 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11904 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11905 | @Override |
| 11906 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11907 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11908 | "setDeviceToDeviceForceEnabled"); |
| 11909 | |
| 11910 | final long identity = Binder.clearCallingIdentity(); |
| 11911 | try { |
| 11912 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11913 | p -> { |
| 11914 | Phone thePhone = p.getImsPhone(); |
| 11915 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11916 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11917 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11918 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11919 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11920 | (ImsPhoneCallTracker) tracker; |
| 11921 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11922 | } |
| 11923 | } |
| 11924 | } |
| 11925 | ); |
| 11926 | } finally { |
| 11927 | Binder.restoreCallingIdentity(identity); |
| 11928 | } |
| 11929 | } |
| 11930 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11931 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11932 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11933 | */ |
| 11934 | @Override |
| 11935 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11936 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11937 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11938 | } |
| 11939 | |
| 11940 | /** |
| 11941 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11942 | */ |
| 11943 | @Override |
| 11944 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11945 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11946 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11947 | enforceModifyPermission(); |
| 11948 | |
| 11949 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11950 | : Boolean.parseBoolean(enabledStr); |
| 11951 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11952 | subId, enabled); |
| 11953 | } |
| 11954 | |
| 11955 | /** |
| 11956 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11957 | */ |
| 11958 | @Override |
| 11959 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11960 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11961 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11962 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11963 | |
| 11964 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11965 | * Overrides the ims feature validation result |
| 11966 | */ |
| 11967 | @Override |
| 11968 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11969 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11970 | "setImsFeatureValidationOverride"); |
| 11971 | |
| 11972 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11973 | : Boolean.parseBoolean(enabledStr); |
| 11974 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11975 | subId, enabled); |
| 11976 | } |
| 11977 | |
| 11978 | /** |
| 11979 | * Gets the ims feature validation override value |
| 11980 | */ |
| 11981 | @Override |
| 11982 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11983 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11984 | "getImsFeatureValidationOverride"); |
| 11985 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11986 | } |
| 11987 | |
| 11988 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11989 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11990 | * their mobile plan. |
| 11991 | */ |
| 11992 | @Override |
| 11993 | public String getMobileProvisioningUrl() { |
| 11994 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11995 | final long identity = Binder.clearCallingIdentity(); |
| 11996 | try { |
| 11997 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11998 | } finally { |
| 11999 | Binder.restoreCallingIdentity(identity); |
| 12000 | } |
| 12001 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12002 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12003 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12004 | * Get the EAB contact from the EAB database. |
| 12005 | */ |
| 12006 | @Override |
| 12007 | public String getContactFromEab(String contact) { |
| 12008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12009 | enforceModifyPermission(); |
| 12010 | final long identity = Binder.clearCallingIdentity(); |
| 12011 | try { |
| 12012 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12013 | } finally { |
| 12014 | Binder.restoreCallingIdentity(identity); |
| 12015 | } |
| 12016 | } |
| 12017 | |
| 12018 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12019 | * Get the EAB capability from the EAB database. |
| 12020 | */ |
| 12021 | @Override |
| 12022 | public String getCapabilityFromEab(String contact) { |
| 12023 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12024 | enforceModifyPermission(); |
| 12025 | final long identity = Binder.clearCallingIdentity(); |
| 12026 | try { |
| 12027 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12028 | } finally { |
| 12029 | Binder.restoreCallingIdentity(identity); |
| 12030 | } |
| 12031 | } |
| 12032 | |
| 12033 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12034 | * Remove the EAB contacts from the EAB database. |
| 12035 | */ |
| 12036 | @Override |
| 12037 | public int removeContactFromEab(int subId, String contacts) { |
| 12038 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12039 | enforceModifyPermission(); |
| 12040 | final long identity = Binder.clearCallingIdentity(); |
| 12041 | try { |
| 12042 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12043 | } finally { |
| 12044 | Binder.restoreCallingIdentity(identity); |
| 12045 | } |
| 12046 | } |
| 12047 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12048 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12049 | public boolean getDeviceUceEnabled() { |
| 12050 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12051 | final long identity = Binder.clearCallingIdentity(); |
| 12052 | try { |
| 12053 | return mApp.getDeviceUceEnabled(); |
| 12054 | } finally { |
| 12055 | Binder.restoreCallingIdentity(identity); |
| 12056 | } |
| 12057 | } |
| 12058 | |
| 12059 | @Override |
| 12060 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12061 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12062 | final long identity = Binder.clearCallingIdentity(); |
| 12063 | try { |
| 12064 | mApp.setDeviceUceEnabled(isEnabled); |
| 12065 | } finally { |
| 12066 | Binder.restoreCallingIdentity(identity); |
| 12067 | } |
| 12068 | } |
| 12069 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12070 | /** |
| 12071 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12072 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12073 | */ |
| 12074 | // Used for SHELL command only right now. |
| 12075 | @Override |
| 12076 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12077 | List<String> featureTags) { |
| 12078 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12079 | "addUceRegistrationOverrideShell"); |
| 12080 | final long identity = Binder.clearCallingIdentity(); |
| 12081 | try { |
| 12082 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12083 | new ArraySet<>(featureTags)); |
| 12084 | } catch (ImsException e) { |
| 12085 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12086 | } finally { |
| 12087 | Binder.restoreCallingIdentity(identity); |
| 12088 | } |
| 12089 | } |
| 12090 | |
| 12091 | /** |
| 12092 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12093 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12094 | */ |
| 12095 | // Used for SHELL command only right now. |
| 12096 | @Override |
| 12097 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12098 | List<String> featureTags) { |
| 12099 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12100 | "removeUceRegistrationOverrideShell"); |
| 12101 | final long identity = Binder.clearCallingIdentity(); |
| 12102 | try { |
| 12103 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12104 | new ArraySet<>(featureTags)); |
| 12105 | } catch (ImsException e) { |
| 12106 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12107 | } finally { |
| 12108 | Binder.restoreCallingIdentity(identity); |
| 12109 | } |
| 12110 | } |
| 12111 | |
| 12112 | /** |
| 12113 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12114 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12115 | */ |
| 12116 | // Used for SHELL command only right now. |
| 12117 | @Override |
| 12118 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12119 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12120 | "clearUceRegistrationOverrideShell"); |
| 12121 | final long identity = Binder.clearCallingIdentity(); |
| 12122 | try { |
| 12123 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12124 | } catch (ImsException e) { |
| 12125 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12126 | } finally { |
| 12127 | Binder.restoreCallingIdentity(identity); |
| 12128 | } |
| 12129 | } |
| 12130 | |
| 12131 | /** |
| 12132 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12133 | */ |
| 12134 | // Used for SHELL command only right now. |
| 12135 | @Override |
| 12136 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12137 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12138 | "getLatestRcsContactUceCapabilityShell"); |
| 12139 | final long identity = Binder.clearCallingIdentity(); |
| 12140 | try { |
| 12141 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12142 | } catch (ImsException e) { |
| 12143 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12144 | } finally { |
| 12145 | Binder.restoreCallingIdentity(identity); |
| 12146 | } |
| 12147 | } |
| 12148 | |
| 12149 | /** |
| 12150 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12151 | * device does not have an active PUBLISH. |
| 12152 | */ |
| 12153 | // Used for SHELL command only right now. |
| 12154 | @Override |
| 12155 | public String getLastUcePidfXmlShell(int subId) { |
| 12156 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12157 | final long identity = Binder.clearCallingIdentity(); |
| 12158 | try { |
| 12159 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12160 | } catch (ImsException e) { |
| 12161 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12162 | } finally { |
| 12163 | Binder.restoreCallingIdentity(identity); |
| 12164 | } |
| 12165 | } |
| 12166 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12167 | /** |
| 12168 | * Remove UCE requests cannot be sent to the network status. |
| 12169 | */ |
| 12170 | // Used for SHELL command only right now. |
| 12171 | @Override |
| 12172 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12173 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12174 | final long identity = Binder.clearCallingIdentity(); |
| 12175 | try { |
| 12176 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12177 | } catch (ImsException e) { |
| 12178 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12179 | } finally { |
| 12180 | Binder.restoreCallingIdentity(identity); |
| 12181 | } |
| 12182 | } |
| 12183 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12184 | /** |
| 12185 | * Remove UCE requests cannot be sent to the network status. |
| 12186 | */ |
| 12187 | // Used for SHELL command only. |
| 12188 | @Override |
| 12189 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12190 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12191 | final long identity = Binder.clearCallingIdentity(); |
| 12192 | try { |
| 12193 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12194 | } catch (ImsException e) { |
| 12195 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12196 | } finally { |
| 12197 | Binder.restoreCallingIdentity(identity); |
| 12198 | } |
| 12199 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12200 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12201 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12202 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12203 | String callingPackage) { |
| 12204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12205 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12206 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12207 | enforceTelephonyFeatureWithException(callingPackage, |
| 12208 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12209 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12210 | final int callingUid = Binder.getCallingUid(); |
| 12211 | // Verify that tha callingPackage belongs to the calling UID |
| 12212 | mApp.getSystemService(AppOpsManager.class) |
| 12213 | .checkPackage(callingUid, callingPackage); |
| 12214 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12215 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12216 | |
| 12217 | final long identity = Binder.clearCallingIdentity(); |
| 12218 | try { |
| 12219 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12220 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12221 | |
| 12222 | if (result instanceof IllegalStateException) { |
| 12223 | throw (IllegalStateException) result; |
| 12224 | } |
| 12225 | } finally { |
| 12226 | Binder.restoreCallingIdentity(identity); |
| 12227 | } |
| 12228 | } |
| 12229 | |
| 12230 | @Override |
| 12231 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12232 | String callingPackage) { |
| 12233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12234 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12235 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12236 | enforceTelephonyFeatureWithException(callingPackage, |
| 12237 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12238 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12239 | final int callingUid = Binder.getCallingUid(); |
| 12240 | // Verify that tha callingPackage belongs to the calling UID |
| 12241 | mApp.getSystemService(AppOpsManager.class) |
| 12242 | .checkPackage(callingUid, callingPackage); |
| 12243 | |
| 12244 | final long identity = Binder.clearCallingIdentity(); |
| 12245 | try { |
| 12246 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12247 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12248 | |
| 12249 | if (result instanceof IllegalStateException) { |
| 12250 | throw (IllegalStateException) result; |
| 12251 | } |
| 12252 | } finally { |
| 12253 | Binder.restoreCallingIdentity(identity); |
| 12254 | } |
| 12255 | } |
| 12256 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12257 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12258 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12259 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12260 | // phone/system process do not have further restriction on request |
| 12261 | return; |
| 12262 | } |
| 12263 | |
| 12264 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12265 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12266 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12267 | context.enforceCallingOrSelfPermission( |
| 12268 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12269 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12270 | } |
| 12271 | |
| 12272 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12273 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12274 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12275 | || info.isEnabled()) { |
| 12276 | throw new IllegalArgumentException( |
| 12277 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12278 | } |
| 12279 | |
| 12280 | // Thresholds length for each RAN need in range. This has been validated in |
| 12281 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12282 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12283 | final int[] thresholds = info.getThresholds(); |
| 12284 | Objects.requireNonNull(thresholds); |
| 12285 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12286 | || thresholds.length |
| 12287 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12288 | throw new IllegalArgumentException( |
| 12289 | "thresholds length is out of range: " + thresholds.length); |
| 12290 | } |
| 12291 | } |
| 12292 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12293 | |
| 12294 | /** |
| 12295 | * Gets the current phone capability. |
| 12296 | * |
| 12297 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12298 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12299 | * It's used to evaluate possible phone config change, for example from single |
| 12300 | * SIM device to multi-SIM device. |
| 12301 | */ |
| 12302 | @Override |
| 12303 | public PhoneCapability getPhoneCapability() { |
| 12304 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12305 | |
| 12306 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12307 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12308 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12309 | final long identity = Binder.clearCallingIdentity(); |
| 12310 | try { |
| 12311 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12312 | } finally { |
| 12313 | Binder.restoreCallingIdentity(identity); |
| 12314 | } |
| 12315 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12316 | |
| 12317 | /** |
| 12318 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12319 | * required to be done shortly after the API is invoked. |
| 12320 | */ |
| 12321 | @Override |
| 12322 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12323 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12324 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12325 | enforceRebootPermission(); |
| 12326 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12327 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12328 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12329 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12330 | final long identity = Binder.clearCallingIdentity(); |
| 12331 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12332 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12333 | } finally { |
| 12334 | Binder.restoreCallingIdentity(identity); |
| 12335 | } |
| 12336 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12337 | |
| 12338 | /** |
| 12339 | * Request to get the current slicing configuration including URSP rules and |
| 12340 | * NSSAIs (configured, allowed and rejected). |
| 12341 | * |
| 12342 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12343 | */ |
| 12344 | @Override |
| 12345 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12346 | TelephonyPermissions |
| 12347 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12348 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12349 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12350 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12351 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12352 | "getSlicingConfig"); |
| 12353 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12354 | final long identity = Binder.clearCallingIdentity(); |
| 12355 | try { |
| 12356 | Phone phone = getDefaultPhone(); |
| 12357 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12358 | } finally { |
| 12359 | Binder.restoreCallingIdentity(identity); |
| 12360 | } |
| 12361 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12362 | |
| 12363 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12364 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12365 | * |
| 12366 | * @param capability The premium capability to check. |
| 12367 | * @param subId The subId to check the premium capability for. |
| 12368 | * |
| 12369 | * @return Whether the given premium capability is available to purchase. |
| 12370 | */ |
| 12371 | @Override |
| 12372 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12373 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12374 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12375 | log("Premium capability " |
| 12376 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12377 | + " is not available for purchase due to missing permissions."); |
| 12378 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12379 | + "permission READ_BASIC_PHONE_STATE."); |
| 12380 | } |
| 12381 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12382 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12383 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12384 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12385 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12386 | if (phone == null) { |
| 12387 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12388 | return false; |
| 12389 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12390 | final long identity = Binder.clearCallingIdentity(); |
| 12391 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12392 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12393 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12394 | } finally { |
| 12395 | Binder.restoreCallingIdentity(identity); |
| 12396 | } |
| 12397 | } |
| 12398 | |
| 12399 | /** |
| 12400 | * Purchase the given premium capability from the carrier. |
| 12401 | * |
| 12402 | * @param capability The premium capability to purchase. |
| 12403 | * @param callback The result of the purchase request. |
| 12404 | * @param subId The subId to purchase the premium capability for. |
| 12405 | */ |
| 12406 | @Override |
| 12407 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12408 | log("purchasePremiumCapability: capability=" |
| 12409 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12410 | + getCurrentPackageName()); |
| 12411 | |
| 12412 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12413 | mApp, "purchasePremiumCapability")) { |
| 12414 | log("purchasePremiumCapability " |
| 12415 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12416 | + " failed due to missing permissions."); |
| 12417 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12418 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12419 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12420 | mApp, "purchasePremiumCapability")) { |
| 12421 | log("purchasePremiumCapability " |
| 12422 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12423 | + " failed due to missing permissions."); |
| 12424 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12425 | } |
| 12426 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12427 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12428 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12429 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12430 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12431 | if (phone == null) { |
| 12432 | try { |
| 12433 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12434 | callback.accept(result); |
| 12435 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12436 | } catch (RemoteException e) { |
| 12437 | String logStr = "Purchase premium capability " |
| 12438 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12439 | + " failed due to RemoteException handling null phone: " + e; |
| 12440 | if (DBG) log(logStr); |
| 12441 | AnomalyReporter.reportAnomaly( |
| 12442 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12443 | } |
| 12444 | return; |
| 12445 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12446 | |
| 12447 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12448 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12449 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12450 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12451 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12452 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12453 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12454 | |
| 12455 | boolean isVisible = false; |
| 12456 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12457 | if (am != null) { |
| 12458 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12459 | if (processes != null) { |
| 12460 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12461 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12462 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12463 | if (process.processName.equals(callingProcess) && process.importance |
| 12464 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12465 | isVisible = true; |
| 12466 | break; |
| 12467 | } |
| 12468 | } |
| 12469 | } |
| 12470 | } |
| 12471 | |
| 12472 | if (!isVisible) { |
| 12473 | try { |
| 12474 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12475 | callback.accept(result); |
| 12476 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12477 | } catch (RemoteException e) { |
| 12478 | String logStr = "Purchase premium capability " |
| 12479 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12480 | + " failed due to RemoteException handling background application: " + e; |
| 12481 | if (DBG) log(logStr); |
| 12482 | AnomalyReporter.reportAnomaly( |
| 12483 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12484 | } |
| 12485 | return; |
| 12486 | } |
| 12487 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12488 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12489 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12490 | } |
| 12491 | |
| 12492 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12493 | * Register an IMS connection state callback |
| 12494 | */ |
| 12495 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12496 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12497 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12498 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12499 | // ImsMmTelManager |
| 12500 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12501 | TelephonyPermissions |
| 12502 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12503 | mApp, subId, "registerImsStateCallback"); |
| 12504 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12505 | // ImsRcsManager or SipDelegateManager |
| 12506 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12507 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12508 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12509 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12510 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12511 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12512 | } |
| 12513 | |
| 12514 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12515 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12516 | "IMS not available on device."); |
| 12517 | } |
| 12518 | |
| 12519 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12520 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12521 | } |
| 12522 | |
| 12523 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12524 | if (controller == null) { |
| 12525 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12526 | "IMS not available on device."); |
| 12527 | } |
| 12528 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12529 | if (callingPackage == null) { |
| 12530 | callingPackage = getCurrentPackageName(); |
| 12531 | } |
| 12532 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12533 | final long token = Binder.clearCallingIdentity(); |
| 12534 | try { |
| 12535 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12536 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12537 | } catch (ImsException e) { |
| 12538 | throw new ServiceSpecificException(e.getCode()); |
| 12539 | } finally { |
| 12540 | Binder.restoreCallingIdentity(token); |
| 12541 | } |
| 12542 | } |
| 12543 | |
| 12544 | /** |
| 12545 | * Unregister an IMS connection state callback |
| 12546 | */ |
| 12547 | @Override |
| 12548 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12549 | final long token = Binder.clearCallingIdentity(); |
| 12550 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12551 | if (controller == null) { |
| 12552 | return; |
| 12553 | } |
| 12554 | try { |
| 12555 | controller.unregisterImsStateCallback(cb); |
| 12556 | } finally { |
| 12557 | Binder.restoreCallingIdentity(token); |
| 12558 | } |
| 12559 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12560 | |
| 12561 | /** |
| 12562 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12563 | * |
| 12564 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12565 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12566 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12567 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12568 | * If there is current registered network this value will be same as the registered cell |
| 12569 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12570 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12571 | * it will be cleared and null will be returned. |
| 12572 | * |
| 12573 | */ |
| 12574 | @Override |
| 12575 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12576 | String callingFeatureId) { |
| 12577 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12578 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12579 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12580 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12581 | .setCallingPackage(callingPackage) |
| 12582 | .setCallingFeatureId(callingFeatureId) |
| 12583 | .setCallingPid(Binder.getCallingPid()) |
| 12584 | .setCallingUid(Binder.getCallingUid()) |
| 12585 | .setMethod("getLastKnownCellIdentity") |
| 12586 | .setLogAsInfo(true) |
| 12587 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12588 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12589 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12590 | .build()); |
| 12591 | |
| 12592 | boolean hasFinePermission = |
| 12593 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12594 | if (!hasFinePermission |
| 12595 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12596 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12597 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12598 | } |
| 12599 | |
| 12600 | final long identity = Binder.clearCallingIdentity(); |
| 12601 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12602 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12603 | if (sst == null) return null; |
| 12604 | return sst.getLastKnownCellIdentity(); |
| 12605 | } finally { |
| 12606 | Binder.restoreCallingIdentity(identity); |
| 12607 | } |
| 12608 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12609 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12610 | /** |
| 12611 | * Sets the modem service class Name that Telephony will bind to. |
| 12612 | * |
| 12613 | * @param serviceName The class name of the modem service. |
| 12614 | * @return true if the operation is succeed, otherwise false. |
| 12615 | */ |
| 12616 | public boolean setModemService(String serviceName) { |
| 12617 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12618 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12619 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12620 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12621 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12622 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12623 | } |
| 12624 | |
| 12625 | /** |
| 12626 | * Return the class name of the currently bounded modem service. |
| 12627 | * |
| 12628 | * @return the class name of the modem service. |
| 12629 | */ |
| 12630 | public String getModemService() { |
| 12631 | String result; |
| 12632 | Log.d(LOG_TAG, "getModemService"); |
| 12633 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12634 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12635 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12636 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12637 | "getModemService"); |
| 12638 | result = mPhoneConfigurationManager.getModemService(); |
| 12639 | Log.d(LOG_TAG, "result = " + result); |
| 12640 | return result; |
| 12641 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12642 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12643 | /** |
| 12644 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12645 | * including carrier config, entitlement server, and config update. |
| 12646 | * |
| 12647 | * @param subId subId The subscription ID of the carrier. |
| 12648 | * |
| 12649 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12650 | * be returned. |
| 12651 | * |
| 12652 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12653 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12654 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12655 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12656 | final long identity = Binder.clearCallingIdentity(); |
| 12657 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12658 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12659 | } finally { |
| 12660 | Binder.restoreCallingIdentity(identity); |
| 12661 | } |
| 12662 | } |
| 12663 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12664 | @Override |
| 12665 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12666 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12667 | mApp.enforceCallingOrSelfPermission( |
| 12668 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12669 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12670 | |
| 12671 | final long identity = Binder.clearCallingIdentity(); |
| 12672 | try { |
| 12673 | Phone phone = getPhone(subId); |
| 12674 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12675 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12676 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12677 | phone.setVoiceServiceStateOverride(hasService); |
| 12678 | } finally { |
| 12679 | Binder.restoreCallingIdentity(identity); |
| 12680 | } |
| 12681 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12682 | |
| 12683 | /** |
| 12684 | * set removable eSIM as default eUICC. |
| 12685 | * |
| 12686 | * @hide |
| 12687 | */ |
| 12688 | @Override |
| 12689 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12690 | enforceModifyPermission(); |
| 12691 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12692 | |
| 12693 | final long identity = Binder.clearCallingIdentity(); |
| 12694 | try { |
| 12695 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12696 | } finally { |
| 12697 | Binder.restoreCallingIdentity(identity); |
| 12698 | } |
| 12699 | } |
| 12700 | |
| 12701 | /** |
| 12702 | * Returns whether the removable eSIM is default eUICC or not. |
| 12703 | * |
| 12704 | * @hide |
| 12705 | */ |
| 12706 | @Override |
| 12707 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12708 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12709 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12710 | |
| 12711 | final long identity = Binder.clearCallingIdentity(); |
| 12712 | try { |
| 12713 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12714 | } finally { |
| 12715 | Binder.restoreCallingIdentity(identity); |
| 12716 | } |
| 12717 | } |
| 12718 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12719 | /** |
| 12720 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12721 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12722 | * application currently configured for this user. |
| 12723 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12724 | * {@code null} if the functionality is not supported. |
| 12725 | * @hide |
| 12726 | */ |
| 12727 | @Override |
| 12728 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12729 | boolean updateIfNeeded) { |
| 12730 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12731 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12732 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12733 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12734 | "getDefaultRespondViaMessageApplication"); |
| 12735 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12736 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12737 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12738 | UserHandle userHandle = null; |
| 12739 | final long identity = Binder.clearCallingIdentity(); |
| 12740 | try { |
| 12741 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12742 | } finally { |
| 12743 | Binder.restoreCallingIdentity(identity); |
| 12744 | } |
| 12745 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12746 | updateIfNeeded, userHandle); |
| 12747 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12748 | |
| 12749 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12750 | * Set whether the device is able to connect with null ciphering or integrity |
| 12751 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12752 | * and all new subscriptions after this. |
| 12753 | * |
| 12754 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12755 | * @hide |
| 12756 | */ |
| 12757 | @Override |
| 12758 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12759 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12760 | enforceModifyPermission(); |
| 12761 | checkForNullCipherAndIntegritySupport(); |
| 12762 | |
| 12763 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12764 | // for listening to these preference changes and applying them immediately. |
| 12765 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12766 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12767 | editor.apply(); |
| 12768 | |
| 12769 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12770 | phone.handleNullCipherEnabledChange(); |
| 12771 | } |
| 12772 | } |
| 12773 | |
| 12774 | |
| 12775 | /** |
| 12776 | * Get whether the device is able to connect with null ciphering or integrity |
| 12777 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12778 | * the state of the radio. |
| 12779 | * |
| 12780 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12781 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12782 | * version for this feature. |
| 12783 | * @hide |
| 12784 | */ |
| 12785 | @Override |
| 12786 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12787 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12788 | enforceReadPermission(); |
| 12789 | checkForNullCipherAndIntegritySupport(); |
| 12790 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12791 | } |
| 12792 | |
| 12793 | private void checkForNullCipherAndIntegritySupport() { |
| 12794 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12795 | throw new UnsupportedOperationException( |
| 12796 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12797 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12798 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12799 | throw new UnsupportedOperationException( |
| 12800 | "Null cipher and integrity operations unsupported by modem"); |
| 12801 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12802 | } |
| 12803 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12804 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12805 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12806 | throw new UnsupportedOperationException( |
| 12807 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12808 | + "above"); |
| 12809 | } |
| 12810 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12811 | throw new UnsupportedOperationException( |
| 12812 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12813 | } |
| 12814 | } |
| 12815 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12816 | private void checkForNullCipherNotificationSupport() { |
| 12817 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12818 | throw new UnsupportedOperationException( |
| 12819 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12820 | } |
| 12821 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12822 | throw new UnsupportedOperationException( |
| 12823 | "Null cipher notification operations unsupported by modem"); |
| 12824 | } |
| 12825 | } |
| 12826 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12827 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12828 | * Get the SIM state for the slot index. |
| 12829 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12830 | * |
| 12831 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12832 | */ |
| 12833 | @Override |
| 12834 | @SimState |
| 12835 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12836 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12837 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12838 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12839 | IccCardConstants.State simState; |
| 12840 | if (slotIndex < 0) { |
| 12841 | simState = IccCardConstants.State.UNKNOWN; |
| 12842 | } else { |
| 12843 | Phone phone = null; |
| 12844 | try { |
| 12845 | phone = PhoneFactory.getPhone(slotIndex); |
| 12846 | } catch (IllegalStateException e) { |
| 12847 | // ignore |
| 12848 | } |
| 12849 | if (phone == null) { |
| 12850 | simState = IccCardConstants.State.UNKNOWN; |
| 12851 | } else { |
| 12852 | IccCard icc = phone.getIccCard(); |
| 12853 | if (icc == null) { |
| 12854 | simState = IccCardConstants.State.UNKNOWN; |
| 12855 | } else { |
| 12856 | simState = icc.getState(); |
| 12857 | } |
| 12858 | } |
| 12859 | } |
| 12860 | return simState.ordinal(); |
| 12861 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12862 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12863 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12864 | boolean enableLogcat, |
| 12865 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12866 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12867 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12868 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 12869 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 12870 | ecdDataBuilder |
| 12871 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 12872 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12873 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12874 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 12875 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12876 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 12877 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12878 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12879 | Executors.newCachedThreadPool(), db, |
| 12880 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12881 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12882 | } |
| 12883 | |
| 12884 | /** |
| 12885 | * Request telephony to persist state for debugging emergency call failures. |
| 12886 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 12887 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12888 | * @param enableLogcat whether to collect logcat output |
| 12889 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12890 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12891 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12892 | */ |
| 12893 | @Override |
| 12894 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12895 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12896 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12897 | boolean enableTelephonyDump) { |
| 12898 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12899 | "persistEmergencyCallDiagnosticData"); |
| 12900 | final long identity = Binder.clearCallingIdentity(); |
| 12901 | try { |
| 12902 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12903 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12904 | |
| 12905 | } finally { |
| 12906 | Binder.restoreCallingIdentity(identity); |
| 12907 | } |
| 12908 | } |
| 12909 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12910 | /** |
| 12911 | * Get current cell broadcast ranges. |
| 12912 | */ |
| 12913 | @Override |
| 12914 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12915 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12916 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12917 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12918 | |
| 12919 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12920 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12921 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12922 | final long identity = Binder.clearCallingIdentity(); |
| 12923 | try { |
| 12924 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12925 | } finally { |
| 12926 | Binder.restoreCallingIdentity(identity); |
| 12927 | } |
| 12928 | } |
| 12929 | |
| 12930 | /** |
| 12931 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12932 | * |
| 12933 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12934 | */ |
| 12935 | @Override |
| 12936 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12937 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12938 | @Nullable IIntegerConsumer callback) { |
| 12939 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12940 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12941 | |
| 12942 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12943 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12944 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12945 | final long identity = Binder.clearCallingIdentity(); |
| 12946 | try { |
| 12947 | Phone phone = getPhoneFromSubId(subId); |
| 12948 | if (DBG) { |
| 12949 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12950 | } |
| 12951 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12952 | if (callback != null) { |
| 12953 | try { |
| 12954 | callback.accept(result); |
| 12955 | } catch (RemoteException e) { |
| 12956 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12957 | } |
| 12958 | } |
| 12959 | }); |
| 12960 | } finally { |
| 12961 | Binder.restoreCallingIdentity(identity); |
| 12962 | } |
| 12963 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12964 | |
| 12965 | /** |
| 12966 | * Returns whether the device supports the domain selection service. |
| 12967 | * |
| 12968 | * @return {@code true} if the device supports the domain selection service. |
| 12969 | */ |
| 12970 | @Override |
| 12971 | public boolean isDomainSelectionSupported() { |
| 12972 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12973 | "isDomainSelectionSupported"); |
| 12974 | |
| 12975 | final long identity = Binder.clearCallingIdentity(); |
| 12976 | try { |
| 12977 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12978 | } finally { |
| 12979 | Binder.restoreCallingIdentity(identity); |
| 12980 | } |
| 12981 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12982 | |
| 12983 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12984 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12985 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12986 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12987 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12988 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12989 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12990 | * {@code false} to disable. |
| 12991 | * @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] | 12992 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12993 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12994 | * |
| 12995 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12996 | */ |
| 12997 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12998 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 12999 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13000 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13001 | if (enableSatellite) { |
| 13002 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13003 | @Override |
| 13004 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13005 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13006 | + ", resultData=" + resultData); |
| 13007 | boolean isAllowed = false; |
| 13008 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13009 | callback::accept); |
| 13010 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13011 | if (resultData != null |
| 13012 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13013 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13014 | } else { |
| 13015 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13016 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13017 | } else { |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13018 | result.accept(resultCode); |
| 13019 | return; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13020 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13021 | if (isAllowed) { |
| 13022 | mSatelliteController.requestSatelliteEnabled( |
| 13023 | subId, enableSatellite, enableDemoMode, callback); |
| 13024 | } else { |
| 13025 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13026 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13027 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13028 | }; |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13029 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13030 | subId, resultReceiver); |
| 13031 | } else { |
| 13032 | // No need to check if satellite is allowed at current location when disabling satellite |
| 13033 | mSatelliteController.requestSatelliteEnabled( |
| 13034 | subId, enableSatellite, enableDemoMode, callback); |
| 13035 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13036 | } |
| 13037 | |
| 13038 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13039 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13040 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13041 | * @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] | 13042 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13043 | * 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] | 13044 | * |
| 13045 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13046 | */ |
| 13047 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13048 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13049 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13050 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13051 | } |
| 13052 | |
| 13053 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13054 | * Request to get whether the satellite service demo mode is enabled. |
| 13055 | * |
| 13056 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13057 | * is enabled for. |
| 13058 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13059 | * if the request is successful or an error code if the request failed. |
| 13060 | * |
| 13061 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13062 | */ |
| 13063 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13064 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13065 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13066 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13067 | } |
| 13068 | |
| 13069 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13070 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13071 | * |
| 13072 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13073 | * is enabled for. |
| 13074 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13075 | * enabled if the request is successful or an error code if the request failed. |
| 13076 | * |
| 13077 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13078 | */ |
| 13079 | @Override |
| 13080 | public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13081 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
| 13082 | result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null); |
| 13083 | } |
| 13084 | |
| 13085 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13086 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13087 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13088 | * @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] | 13089 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13090 | * 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] | 13091 | */ |
| 13092 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13093 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13094 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13095 | } |
| 13096 | |
| 13097 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13098 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13099 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13100 | * @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] | 13101 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13102 | * 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] | 13103 | * |
| 13104 | * @throws SecurityException if the caller doesn't have required permission. |
| 13105 | */ |
| 13106 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13107 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13108 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13109 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13110 | } |
| 13111 | |
| 13112 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13113 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13114 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13115 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13116 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13117 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13118 | * @param resultCallback The callback to get the result of the request. |
| 13119 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13120 | * |
| 13121 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13122 | */ |
| 13123 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13124 | public void startSatelliteTransmissionUpdates(int subId, |
| 13125 | @NonNull IIntegerConsumer resultCallback, |
| 13126 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13127 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13128 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13129 | } |
| 13130 | |
| 13131 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13132 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13133 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13134 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13135 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13136 | * @param resultCallback The callback to get the result of the request. |
| 13137 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13138 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13139 | * |
| 13140 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13141 | */ |
| 13142 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13143 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13144 | @NonNull IIntegerConsumer resultCallback, |
| 13145 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13146 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13147 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13148 | } |
| 13149 | |
| 13150 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13151 | * Register the subscription with a satellite provider. |
| 13152 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13153 | * |
| 13154 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13155 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13156 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13157 | * @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] | 13158 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13159 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13160 | * @return The signal transport used by the caller to cancel the provision request, |
| 13161 | * or {@code null} if the request failed. |
| 13162 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13163 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13164 | */ |
| 13165 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13166 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13167 | @NonNull String token, @NonNull byte[] provisionData, |
| 13168 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13169 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13170 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13171 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13172 | } |
| 13173 | |
| 13174 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13175 | * Unregister the device/subscription with the satellite provider. |
| 13176 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13177 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13178 | * should report as deprovisioned. |
| 13179 | * |
| 13180 | * @param subId The subId of the subscription to be deprovisioned. |
| 13181 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13182 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13183 | * |
| 13184 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13185 | */ |
| 13186 | @Override |
| 13187 | public void deprovisionSatelliteService(int subId, |
| 13188 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13189 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13190 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13191 | } |
| 13192 | |
| 13193 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13194 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13195 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13196 | * @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] | 13197 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13198 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13199 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13200 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13201 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13202 | */ |
| 13203 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13204 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13205 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13206 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13207 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13208 | } |
| 13209 | |
| 13210 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13211 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13212 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13213 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13214 | * @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] | 13215 | * @param callback The callback that was passed to |
| 13216 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13217 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13218 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13219 | */ |
| 13220 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13221 | public void unregisterForSatelliteProvisionStateChanged( |
| 13222 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13223 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13224 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13225 | } |
| 13226 | |
| 13227 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13228 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13229 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13230 | * @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] | 13231 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13232 | * satellite provider if the request is successful or an error code if the |
| 13233 | * request failed. |
| 13234 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13235 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13236 | */ |
| 13237 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13238 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13239 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13240 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13241 | } |
| 13242 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13243 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13244 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13245 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13246 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13247 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13248 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13249 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13250 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13251 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13252 | */ |
| 13253 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13254 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13255 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13256 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13257 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13258 | } |
| 13259 | |
| 13260 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13261 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13262 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13263 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13264 | * @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] | 13265 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13266 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13267 | * |
| 13268 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13269 | */ |
| 13270 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13271 | public void unregisterForModemStateChanged(int subId, |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13272 | @NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13273 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
| 13274 | mSatelliteController.unregisterForModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13275 | } |
| 13276 | |
| 13277 | /** |
| 13278 | * Register to receive incoming datagrams over satellite. |
| 13279 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13280 | * @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] | 13281 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13282 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13283 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13284 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13285 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13286 | */ |
| 13287 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13288 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13289 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13290 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
| 13291 | return mSatelliteController.registerForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13292 | } |
| 13293 | |
| 13294 | /** |
| 13295 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13296 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13297 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13298 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13299 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13300 | * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13301 | * |
| 13302 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13303 | */ |
| 13304 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13305 | public void unregisterForIncomingDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13306 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13307 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
| 13308 | mSatelliteController.unregisterForIncomingDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13309 | } |
| 13310 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13311 | /** |
| 13312 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13313 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13314 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13315 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13316 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13317 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13318 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13319 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13320 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13321 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13322 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13323 | public void pollPendingDatagrams(int subId, IIntegerConsumer callback) { |
| 13324 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
| 13325 | mSatelliteController.pollPendingDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13326 | } |
| 13327 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13328 | /** |
| 13329 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13330 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13331 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13332 | * input to this method. Datagram received here will be passed down to modem without any |
| 13333 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13334 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13335 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13336 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13337 | * SOS_SMS or LOCATION_SHARING. |
| 13338 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13339 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13340 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13341 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13342 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13343 | * |
| 13344 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13345 | */ |
| 13346 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13347 | public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13348 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13349 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13350 | enforceSatelliteCommunicationPermission("sendDatagram"); |
| 13351 | mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI, |
| 13352 | callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13353 | } |
| 13354 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13355 | /** |
| 13356 | * Request to get whether satellite communication is allowed for the current location. |
| 13357 | * |
| 13358 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13359 | * allowed for the current location for. |
| 13360 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13361 | * for the current location if the request is successful or an error code |
| 13362 | * if the request failed. |
| 13363 | * |
| 13364 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13365 | */ |
| 13366 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13367 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13368 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13369 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
| 13370 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId, |
| 13371 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13372 | } |
| 13373 | |
| 13374 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13375 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13376 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13377 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13378 | * @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] | 13379 | * be visible if the request is successful or an error code if the request failed. |
| 13380 | * |
| 13381 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13382 | */ |
| 13383 | @Override |
| 13384 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13385 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13386 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13387 | } |
| 13388 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13389 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13390 | * Inform that Device is aligned to satellite for demo mode. |
| 13391 | * |
| 13392 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13393 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13394 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13395 | * |
| 13396 | * @throws SecurityException if the caller doesn't have required permission. |
| 13397 | */ |
| 13398 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13399 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13400 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13401 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13402 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13403 | } |
| 13404 | |
| 13405 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13406 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13407 | * by modem. |
| 13408 | * |
| 13409 | * @param subId The subId of the subscription to request for. |
| 13410 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame^] | 13411 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13412 | * operation. |
| 13413 | * |
| 13414 | * @throws SecurityException if the caller doesn't have required permission. |
| 13415 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13416 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13417 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13418 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13419 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13420 | final long identity = Binder.clearCallingIdentity(); |
| 13421 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13422 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13423 | } finally { |
| 13424 | Binder.restoreCallingIdentity(identity); |
| 13425 | } |
| 13426 | } |
| 13427 | |
| 13428 | /** |
| 13429 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13430 | * by modem. |
| 13431 | * |
| 13432 | * @param subId The subId of the subscription to request for. |
| 13433 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame^] | 13434 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13435 | * operation. |
| 13436 | * |
| 13437 | * @throws SecurityException if the caller doesn't have required permission. |
| 13438 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13439 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13440 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13441 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13442 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13443 | final long identity = Binder.clearCallingIdentity(); |
| 13444 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13445 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13446 | } finally { |
| 13447 | Binder.restoreCallingIdentity(identity); |
| 13448 | } |
| 13449 | } |
| 13450 | |
| 13451 | /** |
| 13452 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame^] | 13453 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13454 | * |
| 13455 | * @param subId The subId of the subscription to request for. |
| 13456 | * |
| 13457 | * @return Integer array of reasons for disallowing satellite communication. |
| 13458 | * |
| 13459 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13460 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13461 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13462 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13463 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13464 | final long identity = Binder.clearCallingIdentity(); |
| 13465 | try { |
| 13466 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13467 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13468 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13469 | } finally { |
| 13470 | Binder.restoreCallingIdentity(identity); |
| 13471 | } |
| 13472 | } |
| 13473 | |
| 13474 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13475 | * Request to get the signal strength of the satellite connection. |
| 13476 | * |
| 13477 | * @param subId The subId of the subscription to request for. |
| 13478 | * @param result Result receiver to get the error code of the request and the current signal |
| 13479 | * strength of the satellite connection. |
| 13480 | * |
| 13481 | * @throws SecurityException if the caller doesn't have required permission. |
| 13482 | */ |
| 13483 | @Override |
| 13484 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13485 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13486 | final long identity = Binder.clearCallingIdentity(); |
| 13487 | try { |
| 13488 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13489 | } finally { |
| 13490 | Binder.restoreCallingIdentity(identity); |
| 13491 | } |
| 13492 | } |
| 13493 | |
| 13494 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13495 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13496 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13497 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13498 | * |
| 13499 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13500 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13501 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13502 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13503 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13504 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13505 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13506 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13507 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13508 | */ |
| 13509 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13510 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13511 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13512 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13513 | final long identity = Binder.clearCallingIdentity(); |
| 13514 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13515 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13516 | } finally { |
| 13517 | Binder.restoreCallingIdentity(identity); |
| 13518 | } |
| 13519 | } |
| 13520 | |
| 13521 | /** |
| 13522 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13523 | * If callback was not registered before, the request will be ignored. |
| 13524 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13525 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13526 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13527 | * @param callback The callback that was passed to |
| 13528 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13529 | * |
| 13530 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13531 | */ |
| 13532 | @Override |
| 13533 | public void unregisterForNtnSignalStrengthChanged( |
| 13534 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13535 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13536 | final long identity = Binder.clearCallingIdentity(); |
| 13537 | try { |
| 13538 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13539 | } finally { |
| 13540 | Binder.restoreCallingIdentity(identity); |
| 13541 | } |
| 13542 | } |
| 13543 | |
| 13544 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13545 | * Registers for satellite capabilities change event from the satellite service. |
| 13546 | * |
| 13547 | * @param subId The subId of the subscription to request for. |
| 13548 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13549 | * |
| 13550 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13551 | * |
| 13552 | * @throws SecurityException if the caller doesn't have required permission. |
| 13553 | */ |
| 13554 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13555 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13556 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13557 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13558 | final long identity = Binder.clearCallingIdentity(); |
| 13559 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13560 | return mSatelliteController.registerForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13561 | } finally { |
| 13562 | Binder.restoreCallingIdentity(identity); |
| 13563 | } |
| 13564 | } |
| 13565 | |
| 13566 | /** |
| 13567 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13568 | * If callback was not registered before, the request will be ignored. |
| 13569 | * |
| 13570 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13571 | * @param callback The callback that was passed to. |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13572 | * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13573 | * |
| 13574 | * @throws SecurityException if the caller doesn't have required permission. |
| 13575 | */ |
| 13576 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13577 | public void unregisterForCapabilitiesChanged(int subId, |
| 13578 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13579 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13580 | final long identity = Binder.clearCallingIdentity(); |
| 13581 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13582 | mSatelliteController.unregisterForCapabilitiesChanged(subId, callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13583 | } finally { |
| 13584 | Binder.restoreCallingIdentity(identity); |
| 13585 | } |
| 13586 | } |
| 13587 | |
| 13588 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame^] | 13589 | * Registers for the satellite supported state changed. |
| 13590 | * |
| 13591 | * @param subId The subId of the subscription to register for supported state changed. |
| 13592 | * @param callback The callback to handle the satellite supported state changed event. |
| 13593 | * |
| 13594 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13595 | * |
| 13596 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13597 | */ |
| 13598 | @Override |
| 13599 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
| 13600 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13601 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
| 13602 | return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback); |
| 13603 | } |
| 13604 | |
| 13605 | /** |
| 13606 | * Unregisters for the satellite supported state changed. |
| 13607 | * If callback was not registered before, the request will be ignored. |
| 13608 | * |
| 13609 | * @param subId The subId of the subscription to unregister for supported state changed. |
| 13610 | * @param callback The callback that was passed to |
| 13611 | * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}. |
| 13612 | * |
| 13613 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13614 | */ |
| 13615 | @Override |
| 13616 | public void unregisterForSatelliteSupportedStateChanged( |
| 13617 | int subId, @NonNull ISatelliteSupportedStateCallback callback) { |
| 13618 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
| 13619 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback); |
| 13620 | } |
| 13621 | |
| 13622 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13623 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13624 | * |
| 13625 | * @param servicePackageName The package name of the satellite vendor service. |
| 13626 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13627 | * {@code false} otherwise. |
| 13628 | */ |
| 13629 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13630 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13631 | TelephonyPermissions.enforceShellOnly( |
| 13632 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13633 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13634 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13635 | "setSatelliteServicePackageName"); |
| 13636 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13637 | } |
| 13638 | |
| 13639 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13640 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13641 | * |
| 13642 | * @param servicePackageName The package name of the satellite gateway service. |
| 13643 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13644 | * {@code false} otherwise. |
| 13645 | */ |
| 13646 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13647 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13648 | TelephonyPermissions.enforceShellOnly( |
| 13649 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13651 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13652 | "setSatelliteGatewayServicePackageName"); |
| 13653 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13654 | } |
| 13655 | |
| 13656 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13657 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13658 | * |
| 13659 | * @param packageName The package name of the satellite pointing UI app. |
| 13660 | * @param className The class name of the satellite pointing UI app. |
| 13661 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13662 | * {@code false} otherwise. |
| 13663 | */ |
| 13664 | public boolean setSatellitePointingUiClassName( |
| 13665 | @Nullable String packageName, @Nullable String className) { |
| 13666 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13667 | + ", className=" + className); |
| 13668 | TelephonyPermissions.enforceShellOnly( |
| 13669 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13671 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13672 | "setSatelliteGatewayServicePackageName"); |
| 13673 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13674 | } |
| 13675 | |
| 13676 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13677 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13678 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13679 | * listening mode. |
| 13680 | * |
| 13681 | * @param timeoutMillis The timeout duration in millisecond. |
| 13682 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13683 | */ |
| 13684 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13685 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13686 | TelephonyPermissions.enforceShellOnly( |
| 13687 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13689 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13690 | "setSatelliteListeningTimeoutDuration"); |
| 13691 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13692 | } |
| 13693 | |
| 13694 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13695 | * This API can be used by only CTS to override the timeout durations used by the |
| 13696 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13697 | * |
| 13698 | * @param timeoutMillis The timeout duration in millisecond. |
| 13699 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13700 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13701 | public boolean setDatagramControllerTimeoutDuration( |
| 13702 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13703 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13704 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13705 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13706 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13707 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13708 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 13709 | "setDatagramControllerTimeoutDuration"); |
| 13710 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 13711 | reset, timeoutType, timeoutMillis); |
| 13712 | } |
| 13713 | |
| 13714 | /** |
| 13715 | * This API can be used by only CTS to override the timeout durations used by the |
| 13716 | * SatelliteController module. |
| 13717 | * |
| 13718 | * @param timeoutMillis The timeout duration in millisecond. |
| 13719 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13720 | */ |
| 13721 | public boolean setSatelliteControllerTimeoutDuration( |
| 13722 | boolean reset, int timeoutType, long timeoutMillis) { |
| 13723 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 13724 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 13725 | TelephonyPermissions.enforceShellOnly( |
| 13726 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 13727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13728 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13729 | "setSatelliteControllerTimeoutDuration"); |
| 13730 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 13731 | reset, timeoutType, timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13732 | } |
| 13733 | |
| 13734 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13735 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13736 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13737 | * |
| 13738 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13739 | * of the following values to enable the override: |
| 13740 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13741 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13742 | * To disable the override, use -1 for handoverType. |
| 13743 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13744 | * delaySeconds after the emergency call starts. |
| 13745 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13746 | */ |
| 13747 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13748 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13749 | TelephonyPermissions.enforceShellOnly( |
| 13750 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13752 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13753 | "setEmergencyCallToSatelliteHandoverType"); |
| 13754 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13755 | handoverType, delaySeconds); |
| 13756 | } |
| 13757 | |
| 13758 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 13759 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 13760 | * |
| 13761 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 13762 | * otherwise. |
| 13763 | * @param isProvisioned The overriding provision status. |
| 13764 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 13765 | */ |
| 13766 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 13767 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 13768 | + ", isProvisioned=" + isProvisioned); |
| 13769 | TelephonyPermissions.enforceShellOnly( |
| 13770 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 13771 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13772 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13773 | "setOemEnabledSatelliteProvisionStatus"); |
| 13774 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 13775 | } |
| 13776 | |
| 13777 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13778 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13779 | * |
| 13780 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13781 | */ |
| 13782 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13783 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13784 | long locationCountryCodeTimestampNanos) { |
| 13785 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13786 | + String.join(", ", currentNetworkCountryCodes) |
| 13787 | + ", locationCountryCode=" + locationCountryCode |
| 13788 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13789 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13790 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13791 | TelephonyPermissions.enforceShellOnly( |
| 13792 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13793 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13794 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13795 | "setCachedLocationCountryCode"); |
| 13796 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13797 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13798 | locationCountryCodeTimestampNanos); |
| 13799 | } |
| 13800 | |
| 13801 | /** |
| 13802 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13803 | * access controller. |
| 13804 | * |
| 13805 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13806 | * otherwise. |
| 13807 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13808 | */ |
| 13809 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13810 | String s2CellFile, long locationFreshDurationNanos, |
| 13811 | List<String> satelliteCountryCodes) { |
| 13812 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13813 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13814 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13815 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13816 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13817 | TelephonyPermissions.enforceShellOnly( |
| 13818 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13819 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13820 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13821 | "setSatelliteAccessControlOverlayConfigs"); |
| 13822 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13823 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13824 | } |
| 13825 | |
| 13826 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13827 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13828 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13829 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13830 | * |
| 13831 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13832 | * satellite modem or not. |
| 13833 | * |
| 13834 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13835 | */ |
| 13836 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13837 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13838 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13839 | + "disabled"); |
| 13840 | return false; |
| 13841 | } |
| 13842 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13843 | TelephonyPermissions.enforceShellOnly( |
| 13844 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13846 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13847 | "setShouldSendDatagramToModemInDemoMode"); |
| 13848 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13849 | shouldSendToModemInDemoMode); |
| 13850 | } |
| 13851 | |
| 13852 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 13853 | * Sets the service defined in ComponentName to be bound. |
| 13854 | * |
| 13855 | * This should only be used for testing. |
| 13856 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 13857 | * {@code false} otherwise. |
| 13858 | */ |
| 13859 | @Override |
| 13860 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 13861 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 13862 | |
| 13863 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13864 | "setDomainSelectionServiceOverride"); |
| 13865 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13866 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 13867 | |
| 13868 | final long identity = Binder.clearCallingIdentity(); |
| 13869 | try { |
| 13870 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13871 | return DomainSelectionResolver.getInstance() |
| 13872 | .setDomainSelectionServiceOverride(componentName); |
| 13873 | } |
| 13874 | } finally { |
| 13875 | Binder.restoreCallingIdentity(identity); |
| 13876 | } |
| 13877 | return false; |
| 13878 | } |
| 13879 | |
| 13880 | /** |
| 13881 | * Clears the DomainSelectionService override. |
| 13882 | * |
| 13883 | * This should only be used for testing. |
| 13884 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 13885 | * {@code false} otherwise. |
| 13886 | */ |
| 13887 | @Override |
| 13888 | public boolean clearDomainSelectionServiceOverride() { |
| 13889 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 13890 | |
| 13891 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 13892 | "clearDomainSelectionServiceOverride"); |
| 13893 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13894 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 13895 | |
| 13896 | final long identity = Binder.clearCallingIdentity(); |
| 13897 | try { |
| 13898 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13899 | return DomainSelectionResolver.getInstance() |
| 13900 | .clearDomainSelectionServiceOverride(); |
| 13901 | } |
| 13902 | } finally { |
| 13903 | Binder.restoreCallingIdentity(identity); |
| 13904 | } |
| 13905 | return false; |
| 13906 | } |
| 13907 | |
| 13908 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13909 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 13910 | * |
| 13911 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 13912 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 13913 | * identifier is sent in the clear, which has privacy implications for the user. |
| 13914 | * |
| 13915 | * @param enable if notifications about disclosure events should be enabled |
| 13916 | * @throws SecurityException if the caller does not have the required privileges |
| 13917 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13918 | */ |
| 13919 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13920 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13921 | enforceModifyPermission(); |
| 13922 | checkForIdentifierDisclosureNotificationSupport(); |
| 13923 | |
| 13924 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13925 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 13926 | editor.apply(); |
| 13927 | |
| 13928 | // Each phone instance is responsible for updating its respective modem immediately |
| 13929 | // after we've made a preference change. |
| 13930 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13931 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 13932 | } |
| 13933 | } |
| 13934 | |
| 13935 | /** |
| 13936 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 13937 | * |
| 13938 | * @throws SecurityException if the caller does not have the required privileges |
| 13939 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13940 | */ |
| 13941 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13942 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13943 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 13944 | checkForIdentifierDisclosureNotificationSupport(); |
| 13945 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 13946 | } |
| 13947 | |
| 13948 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 13949 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 13950 | * are in use by the cellular modem. |
| 13951 | * |
| 13952 | * @throws IllegalStateException if the Telephony process is not currently available |
| 13953 | * @throws SecurityException if the caller does not have the required privileges |
| 13954 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 13955 | * and integrity algorithms in use |
| 13956 | * @hide |
| 13957 | */ |
| 13958 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 13959 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 13960 | enforceModifyPermission(); |
| 13961 | checkForNullCipherNotificationSupport(); |
| 13962 | |
| 13963 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13964 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 13965 | editor.apply(); |
| 13966 | |
| 13967 | // Each phone instance is responsible for updating its respective modem immediately |
| 13968 | // after a preference change. |
| 13969 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13970 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 13971 | } |
| 13972 | } |
| 13973 | |
| 13974 | /** |
| 13975 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 13976 | * cellular modem. |
| 13977 | * |
| 13978 | * @throws IllegalStateException if the Telephony process is not currently available |
| 13979 | * @throws SecurityException if the caller does not have the required privileges |
| 13980 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 13981 | * and integrity algorithms in use |
| 13982 | * @hide |
| 13983 | */ |
| 13984 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 13985 | public boolean isNullCipherNotificationsEnabled() { |
| 13986 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 13987 | checkForNullCipherNotificationSupport(); |
| 13988 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 13989 | } |
| 13990 | |
| 13991 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13992 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 13993 | * |
| 13994 | * <p>This method behaves in one of the following ways: |
| 13995 | * <ul> |
| 13996 | * <li>return true : if the calling package has the appop permission {@link |
| 13997 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 13998 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 13999 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14000 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14001 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14002 | * </ul> |
| 14003 | */ |
| 14004 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14005 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14006 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14007 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14008 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14009 | return true; |
| 14010 | } |
| 14011 | } |
| 14012 | return false; |
| 14013 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14014 | |
| 14015 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14016 | * @return The subscription manager service instance. |
| 14017 | */ |
| 14018 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14019 | return SubscriptionManagerService.getInstance(); |
| 14020 | } |
| 14021 | |
| 14022 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14023 | * Class binds the consumer[callback] and carrierId. |
| 14024 | */ |
| 14025 | private static class CallerCallbackInfo { |
| 14026 | private final Consumer<Integer> mConsumer; |
| 14027 | private final int mCarrierId; |
| 14028 | |
| 14029 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 14030 | mConsumer = consumer; |
| 14031 | mCarrierId = carrierId; |
| 14032 | } |
| 14033 | |
| 14034 | public Consumer<Integer> getConsumer() { |
| 14035 | return mConsumer; |
| 14036 | } |
| 14037 | |
| 14038 | public int getCarrierId() { |
| 14039 | return mCarrierId; |
| 14040 | } |
| 14041 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14042 | |
| 14043 | /* |
| 14044 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14045 | * But the context that is passed in is unused if the phone app is already alive. |
| 14046 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14047 | */ |
| 14048 | @VisibleForTesting |
| 14049 | public void setPackageManager(PackageManager packageManager) { |
| 14050 | mPackageManager = packageManager; |
| 14051 | } |
| 14052 | |
| 14053 | /* |
| 14054 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14055 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14056 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14057 | */ |
| 14058 | @VisibleForTesting |
| 14059 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14060 | mFeatureFlags = featureFlags; |
| 14061 | } |
| 14062 | |
| 14063 | /** |
| 14064 | * Make sure the device has required telephony feature |
| 14065 | * |
| 14066 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14067 | */ |
| 14068 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14069 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14070 | if (callingPackage == null || mPackageManager == null) { |
| 14071 | return; |
| 14072 | } |
| 14073 | |
| 14074 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14075 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
| 14076 | Binder.getCallingUserHandle())) { |
| 14077 | return; |
| 14078 | } |
| 14079 | |
| 14080 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14081 | throw new UnsupportedOperationException( |
| 14082 | methodName + " is unsupported without " + telephonyFeature); |
| 14083 | } |
| 14084 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14085 | } |