Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS; |
| 20 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 22 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 23 | import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 24 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 26 | import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; |
| 27 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED; |
| 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 29 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 30 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 31 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 32 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 34 | 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] | 35 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 36 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 37 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 38 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 39 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 41 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 43 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 44 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 45 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 46 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 47 | import android.compat.annotation.ChangeId; |
| 48 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 49 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 50 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 51 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.content.Context; |
| 53 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 54 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 55 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 56 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.net.Uri; |
| 58 | import android.os.AsyncResult; |
| 59 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 60 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 62 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 64 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 65 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 66 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | import android.os.Looper; |
| 68 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 69 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 70 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 71 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 72 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 73 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 74 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 75 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 76 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 77 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 78 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 79 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 80 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 81 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 82 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 83 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 84 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 85 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 86 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 87 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 88 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 89 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 90 | import android.telephony.AccessNetworkConstants; |
| 91 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 92 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 93 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 94 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 95 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 96 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 97 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 98 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 99 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 100 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 101 | import android.telephony.CellIdentityCdma; |
| 102 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 103 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 104 | import android.telephony.CellInfoGsm; |
| 105 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 106 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 107 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 108 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 109 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 110 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 111 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 112 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 113 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 114 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 115 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 116 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 117 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 118 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 120 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 121 | import android.telephony.SignalStrengthUpdateRequest; |
| 122 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 123 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 124 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 125 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 126 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 127 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 128 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 130 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 131 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 132 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 133 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 134 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 135 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 136 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 137 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 138 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 139 | import android.telephony.gba.GbaAuthRequest; |
| 140 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 141 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 142 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 143 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 144 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 145 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 146 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 147 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 153 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 154 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 155 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 156 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 158 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 160 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 162 | import android.telephony.satellite.NtnSignalStrength; |
| 163 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 164 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 165 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 166 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 167 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 169 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 170 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 171 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 173 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 174 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 175 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 176 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 177 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 178 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 193 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 210 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 215 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 216 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 217 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 218 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 220 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 221 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 222 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 224 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 226 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 227 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 230 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 231 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 232 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 233 | import com.android.internal.telephony.uicc.IccIoResult; |
| 234 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 235 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 236 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 238 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 239 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 242 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 243 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 244 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 245 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 246 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 247 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 248 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 249 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 250 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 251 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 252 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 253 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 254 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 255 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 256 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 257 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 258 | import com.android.services.telephony.TelecomAccountRegistry; |
| 259 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 260 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 261 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 262 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 263 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 264 | import java.io.IOException; |
| 265 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 266 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 267 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 268 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 269 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 270 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 271 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 272 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 273 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 274 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 275 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 276 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 277 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 278 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 279 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 280 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 281 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 282 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 283 | |
| 284 | /** |
| 285 | * Implementation of the ITelephony interface. |
| 286 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 287 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 288 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 289 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 290 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 291 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 292 | |
| 293 | // Message codes used with mMainThreadHandler |
| 294 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 295 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 296 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 297 | private static final int CMD_OPEN_CHANNEL = 9; |
| 298 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 299 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 300 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 301 | private static final int CMD_NV_READ_ITEM = 13; |
| 302 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 303 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 304 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 305 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 306 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 307 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 308 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 309 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 310 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 311 | private static final int CMD_SEND_ENVELOPE = 25; |
| 312 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 313 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 314 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 315 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 316 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 317 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 318 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 319 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 320 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 321 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 322 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 323 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 324 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 325 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 326 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 327 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 328 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 329 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 330 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 331 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 332 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 333 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 334 | private static final int CMD_SWITCH_SLOTS = 50; |
| 335 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 336 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 337 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 338 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 339 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 340 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 341 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 342 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 343 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 344 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 345 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 346 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 347 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 348 | private static final int CMD_MODEM_REBOOT = 64; |
| 349 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 350 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 351 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 352 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 353 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 354 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 355 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 356 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 357 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 358 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 359 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 360 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 361 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 362 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 363 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 364 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 365 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 366 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 367 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 368 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 369 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 370 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 371 | private static final int CMD_GET_CALL_WAITING = 87; |
| 372 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 373 | private static final int CMD_SET_CALL_WAITING = 89; |
| 374 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 375 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 376 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 377 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 378 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 379 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 380 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 381 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 382 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 383 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 384 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 385 | private static final int CMD_SET_SIM_POWER = 101; |
| 386 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 387 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 388 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 389 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 390 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 391 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 392 | 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] | 393 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 394 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 395 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 396 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 397 | private static final int CMD_ENABLE_VONR = 113; |
| 398 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 399 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 400 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 401 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 402 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 403 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 404 | // Parameters of select command. |
| 405 | private static final int SELECT_COMMAND = 0xA4; |
| 406 | private static final int SELECT_P1 = 0x04; |
| 407 | private static final int SELECT_P2 = 0; |
| 408 | private static final int SELECT_P3 = 0x10; |
| 409 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 410 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 411 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 412 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 413 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | /** The singleton instance. */ |
| 416 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 417 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 419 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 420 | private FeatureFlags mFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 421 | private final CallManager mCM; |
| 422 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 423 | |
| 424 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 425 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 426 | private final UserManager mUserManager; |
| 427 | private final AppOpsManager mAppOps; |
| 428 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 429 | private final SharedPreferences mTelephonySharedPreferences; |
| 430 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 431 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 432 | private PackageManager mPackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 434 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 435 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 436 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 437 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 438 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 439 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 440 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 441 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 442 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 443 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 444 | // String to store multi SIM allowed |
| 445 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 446 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 447 | // The AID of ISD-R. |
| 448 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 449 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 450 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 451 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 452 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 453 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 454 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 455 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 456 | 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] | 457 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 458 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 459 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 460 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 461 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 462 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 463 | */ |
| 464 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 465 | "reset_network_erase_modem_config_enabled"; |
| 466 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 467 | 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] | 468 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 469 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 470 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 471 | /** |
| 472 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 473 | * one ICCID active at the same time. |
| 474 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 475 | * |
| 476 | * @hide |
| 477 | */ |
| 478 | @ChangeId |
| 479 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 480 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 481 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 482 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 483 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 484 | * operation fails. |
| 485 | */ |
| 486 | @ChangeId |
| 487 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 488 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 489 | |
| 490 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | * A request object to use for transmitting data to an ICC. |
| 492 | */ |
| 493 | private static final class IccAPDUArgument { |
| 494 | public int channel, cla, command, p1, p2, p3; |
| 495 | public String data; |
| 496 | |
| 497 | public IccAPDUArgument(int channel, int cla, int command, |
| 498 | int p1, int p2, int p3, String data) { |
| 499 | this.channel = channel; |
| 500 | this.cla = cla; |
| 501 | this.command = command; |
| 502 | this.p1 = p1; |
| 503 | this.p2 = p2; |
| 504 | this.p3 = p3; |
| 505 | this.data = data; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 510 | * A request object to use for transmitting data to an ICC. |
| 511 | */ |
| 512 | private static final class ManualNetworkSelectionArgument { |
| 513 | public OperatorInfo operatorInfo; |
| 514 | public boolean persistSelection; |
| 515 | |
| 516 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 517 | this.operatorInfo = operatorInfo; |
| 518 | this.persistSelection = persistSelection; |
| 519 | } |
| 520 | } |
| 521 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 522 | private static final class PurchasePremiumCapabilityArgument { |
| 523 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 524 | public @NonNull IIntegerConsumer callback; |
| 525 | |
| 526 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 527 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 528 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 529 | this.callback = callback; |
| 530 | } |
| 531 | } |
| 532 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 533 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 534 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 535 | * request after sending. The main thread will notify the request when it is complete. |
| 536 | */ |
| 537 | private static final class MainThreadRequest { |
| 538 | /** The argument to use for the request */ |
| 539 | public Object argument; |
| 540 | /** The result of the request that is run on the main thread */ |
| 541 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 542 | // The subscriber id that this request applies to. Defaults to |
| 543 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 544 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 545 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 546 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 547 | public Phone phone; |
| 548 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 549 | public WorkSource workSource; |
| 550 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 551 | public MainThreadRequest(Object argument) { |
| 552 | this.argument = argument; |
| 553 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 554 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 555 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 556 | this.argument = argument; |
| 557 | if (phone != null) { |
| 558 | this.phone = phone; |
| 559 | } |
| 560 | this.workSource = workSource; |
| 561 | } |
| 562 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 563 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 564 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 565 | if (subId != null) { |
| 566 | this.subId = subId; |
| 567 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 568 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 572 | private static final class IncomingThirdPartyCallArgs { |
| 573 | public final ComponentName component; |
| 574 | public final String callId; |
| 575 | public final String callerDisplayName; |
| 576 | |
| 577 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 578 | String callerDisplayName) { |
| 579 | this.component = component; |
| 580 | this.callId = callId; |
| 581 | this.callerDisplayName = callerDisplayName; |
| 582 | } |
| 583 | } |
| 584 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 585 | /** |
| 586 | * A handler that processes messages on the main thread in the phone process. Since many |
| 587 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 588 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 589 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 590 | * on, which will be notified when the operation completes and will contain the result of the |
| 591 | * request. |
| 592 | * |
| 593 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 594 | * note that request.result must be set to something non-null for the calling thread to |
| 595 | * unblock. |
| 596 | */ |
| 597 | private final class MainThreadHandler extends Handler { |
| 598 | @Override |
| 599 | public void handleMessage(Message msg) { |
| 600 | MainThreadRequest request; |
| 601 | Message onCompleted; |
| 602 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 603 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 604 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 605 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 606 | |
| 607 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | case CMD_HANDLE_USSD_REQUEST: { |
| 609 | request = (MainThreadRequest) msg.obj; |
| 610 | final Phone phone = getPhoneFromRequest(request); |
| 611 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 612 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 613 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 614 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 615 | if (!isUssdApiAllowed(request.subId)) { |
| 616 | // Carrier does not support use of this API, return failure. |
| 617 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 618 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 619 | Bundle returnData = new Bundle(); |
| 620 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 621 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 622 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 623 | request.result = true; |
| 624 | notifyRequester(request); |
| 625 | return; |
| 626 | } |
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 | try { |
| 629 | request.result = phone != null |
| 630 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 631 | } catch (CallStateException cse) { |
| 632 | request.result = false; |
| 633 | } |
| 634 | // Wake up the requesting thread |
| 635 | notifyRequester(request); |
| 636 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 639 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 640 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 641 | final Phone phone = getPhoneFromRequest(request); |
| 642 | request.result = phone != null ? |
| 643 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 644 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 645 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 646 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 647 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 648 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 649 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 650 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 652 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 653 | uiccPort = getUiccPortFromRequest(request); |
| 654 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 655 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 656 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 658 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 660 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 661 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 662 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 663 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 664 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 665 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | break; |
| 667 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | ar = (AsyncResult) msg.obj; |
| 670 | request = (MainThreadRequest) ar.userObj; |
| 671 | if (ar.exception == null && ar.result != null) { |
| 672 | request.result = ar.result; |
| 673 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 674 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | if (ar.result == null) { |
| 676 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 677 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 679 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | } else { |
| 681 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 682 | } |
| 683 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 684 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 685 | break; |
| 686 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 687 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 688 | request = (MainThreadRequest) msg.obj; |
| 689 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 690 | uiccPort = getUiccPortFromRequest(request); |
| 691 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 692 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 693 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 694 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | } else { |
| 696 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 697 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 698 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 699 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 700 | iccArgument.p2, |
| 701 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 702 | } |
| 703 | break; |
| 704 | |
| 705 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 706 | ar = (AsyncResult) msg.obj; |
| 707 | request = (MainThreadRequest) ar.userObj; |
| 708 | if (ar.exception == null && ar.result != null) { |
| 709 | request.result = ar.result; |
| 710 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 711 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 712 | if (ar.result == null) { |
| 713 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 714 | } else if (ar.exception instanceof CommandException) { |
| 715 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 716 | ar.exception); |
| 717 | } else { |
| 718 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 719 | } |
| 720 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 721 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case CMD_EXCHANGE_SIM_IO: |
| 725 | request = (MainThreadRequest) msg.obj; |
| 726 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 727 | uiccPort = getUiccPortFromRequest(request); |
| 728 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 729 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 730 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 731 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 732 | } else { |
| 733 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 734 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 735 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 736 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 737 | iccArgument.data, onCompleted); |
| 738 | } |
| 739 | break; |
| 740 | |
| 741 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 742 | ar = (AsyncResult) msg.obj; |
| 743 | request = (MainThreadRequest) ar.userObj; |
| 744 | if (ar.exception == null && ar.result != null) { |
| 745 | request.result = ar.result; |
| 746 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 747 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 748 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 749 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 750 | break; |
| 751 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 752 | case CMD_SEND_ENVELOPE: |
| 753 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 754 | uiccPort = getUiccPortFromRequest(request); |
| 755 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 756 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 757 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 758 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 759 | } else { |
| 760 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 761 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 762 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case EVENT_SEND_ENVELOPE_DONE: |
| 766 | ar = (AsyncResult) msg.obj; |
| 767 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 768 | if (ar.exception == null && ar.result != null) { |
| 769 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 770 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 771 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 772 | if (ar.result == null) { |
| 773 | loge("sendEnvelopeWithStatus: Empty response"); |
| 774 | } else if (ar.exception instanceof CommandException) { |
| 775 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 776 | ar.exception); |
| 777 | } else { |
| 778 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 779 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 780 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 781 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 782 | break; |
| 783 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 784 | case CMD_OPEN_CHANNEL: |
| 785 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 786 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 787 | IccLogicalChannelRequest openChannelRequest = |
| 788 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 789 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 790 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 791 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 792 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 793 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 794 | } else { |
| 795 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 796 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 797 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 798 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | break; |
| 800 | |
| 801 | case EVENT_OPEN_CHANNEL_DONE: |
| 802 | ar = (AsyncResult) msg.obj; |
| 803 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 804 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 805 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 806 | int[] result = (int[]) ar.result; |
| 807 | int channelId = result[0]; |
| 808 | byte[] selectResponse = null; |
| 809 | if (result.length > 1) { |
| 810 | selectResponse = new byte[result.length - 1]; |
| 811 | for (int i = 1; i < result.length; ++i) { |
| 812 | selectResponse[i - 1] = (byte) result[i]; |
| 813 | } |
| 814 | } |
| 815 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 816 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 817 | |
| 818 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 819 | if (uiccPort == null) { |
| 820 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 821 | } else { |
| 822 | IccLogicalChannelRequest channelRequest = |
| 823 | (IccLogicalChannelRequest) request.argument; |
| 824 | channelRequest.channel = channelId; |
| 825 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 826 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 827 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 828 | if (ar.result == null) { |
| 829 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 830 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 831 | if (ar.exception != null) { |
| 832 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 833 | } |
| 834 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 835 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 836 | if (ar.exception instanceof CommandException) { |
| 837 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 838 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 839 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 840 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 841 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 842 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 846 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 847 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 848 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 849 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case CMD_CLOSE_CHANNEL: |
| 853 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 854 | uiccPort = getUiccPortFromRequest(request); |
| 855 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 856 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 857 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 858 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 859 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 860 | } else { |
| 861 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 862 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 863 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 867 | ar = (AsyncResult) msg.obj; |
| 868 | request = (MainThreadRequest) ar.userObj; |
| 869 | if (ar.exception == null) { |
| 870 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 871 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 872 | if (uiccPort == null) { |
| 873 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 874 | } else { |
| 875 | final int channelId = (Integer) request.argument; |
| 876 | uiccPort.onLogicalChannelClosed(channelId); |
| 877 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 878 | } else { |
| 879 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 880 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 881 | if (ar.exception instanceof CommandException) { |
| 882 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 883 | CommandException.Error error = |
| 884 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 885 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 886 | // should only throw exceptions from the binder threads. |
| 887 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 888 | "iccCloseLogicalChannel: invalid argument "); |
| 889 | } |
| 890 | } else { |
| 891 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 892 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 893 | request.result = (exception != null) ? exception : |
| 894 | new IllegalStateException( |
| 895 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 896 | } |
| 897 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 898 | break; |
| 899 | |
| 900 | case CMD_NV_READ_ITEM: |
| 901 | request = (MainThreadRequest) msg.obj; |
| 902 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 903 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 904 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 905 | break; |
| 906 | |
| 907 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 908 | ar = (AsyncResult) msg.obj; |
| 909 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 910 | if (ar.exception == null && ar.result != null) { |
| 911 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 912 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 913 | request.result = ""; |
| 914 | if (ar.result == null) { |
| 915 | loge("nvReadItem: Empty response"); |
| 916 | } else if (ar.exception instanceof CommandException) { |
| 917 | loge("nvReadItem: CommandException: " + |
| 918 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 919 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 920 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 921 | } |
| 922 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 923 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 924 | break; |
| 925 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 926 | case CMD_NV_WRITE_ITEM: |
| 927 | request = (MainThreadRequest) msg.obj; |
| 928 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 929 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 930 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 931 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 932 | break; |
| 933 | |
| 934 | case EVENT_NV_WRITE_ITEM_DONE: |
| 935 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 936 | break; |
| 937 | |
| 938 | case CMD_NV_WRITE_CDMA_PRL: |
| 939 | request = (MainThreadRequest) msg.obj; |
| 940 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 941 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 942 | break; |
| 943 | |
| 944 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 945 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 946 | break; |
| 947 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 948 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 949 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 950 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 951 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 952 | break; |
| 953 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 954 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 955 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 956 | break; |
| 957 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 958 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 959 | request = (MainThreadRequest) msg.obj; |
| 960 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 961 | request); |
| 962 | Phone phone = getPhoneFromRequest(request); |
| 963 | if (phone != null) { |
| 964 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 965 | } else { |
| 966 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 967 | request.result = false; |
| 968 | notifyRequester(request); |
| 969 | } |
| 970 | break; |
| 971 | } |
| 972 | |
| 973 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 974 | ar = (AsyncResult) msg.obj; |
| 975 | request = (MainThreadRequest) ar.userObj; |
| 976 | if (ar.exception == null && ar.result != null) { |
| 977 | request.result = ar.result; |
| 978 | } else { |
| 979 | // request.result must be set to something non-null |
| 980 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 981 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 982 | request.result = ar.result; |
| 983 | } else { |
| 984 | request.result = false; |
| 985 | } |
| 986 | if (ar.result == null) { |
| 987 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 988 | } else if (ar.exception instanceof CommandException) { |
| 989 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 990 | + ar.exception); |
| 991 | } else { |
| 992 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 993 | } |
| 994 | } |
| 995 | notifyRequester(request); |
| 996 | break; |
| 997 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 998 | case CMD_IS_VONR_ENABLED: { |
| 999 | request = (MainThreadRequest) msg.obj; |
| 1000 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1001 | request); |
| 1002 | Phone phone = getPhoneFromRequest(request); |
| 1003 | if (phone != null) { |
| 1004 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1005 | } else { |
| 1006 | loge("isVoNrEnabled: No phone object"); |
| 1007 | request.result = false; |
| 1008 | notifyRequester(request); |
| 1009 | } |
| 1010 | break; |
| 1011 | } |
| 1012 | |
| 1013 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | if (ar.exception == null && ar.result != null) { |
| 1017 | request.result = ar.result; |
| 1018 | } else { |
| 1019 | // request.result must be set to something non-null |
| 1020 | // for the calling thread to unblock |
| 1021 | if (ar.result != null) { |
| 1022 | request.result = ar.result; |
| 1023 | } else { |
| 1024 | request.result = false; |
| 1025 | } |
| 1026 | if (ar.result == null) { |
| 1027 | loge("isVoNrEnabled: Empty response"); |
| 1028 | } else if (ar.exception instanceof CommandException) { |
| 1029 | loge("isVoNrEnabled: CommandException: " |
| 1030 | + ar.exception); |
| 1031 | } else { |
| 1032 | loge("isVoNrEnabled: Unknown exception"); |
| 1033 | } |
| 1034 | } |
| 1035 | notifyRequester(request); |
| 1036 | break; |
| 1037 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1038 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1039 | request = (MainThreadRequest) msg.obj; |
| 1040 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1041 | Phone phone = getPhoneFromRequest(request); |
| 1042 | if (phone != null) { |
| 1043 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1044 | request.workSource); |
| 1045 | } else { |
| 1046 | loge("enableNrDualConnectivity: No phone object"); |
| 1047 | request.result = |
| 1048 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1049 | notifyRequester(request); |
| 1050 | } |
| 1051 | break; |
| 1052 | } |
| 1053 | |
| 1054 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1055 | ar = (AsyncResult) msg.obj; |
| 1056 | request = (MainThreadRequest) ar.userObj; |
| 1057 | if (ar.exception == null) { |
| 1058 | request.result = |
| 1059 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1060 | } else { |
| 1061 | request.result = |
| 1062 | TelephonyManager |
| 1063 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1064 | if (ar.exception instanceof CommandException) { |
| 1065 | CommandException.Error error = |
| 1066 | ((CommandException) (ar.exception)).getCommandError(); |
| 1067 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1068 | request.result = |
| 1069 | TelephonyManager |
| 1070 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1071 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1072 | request.result = |
| 1073 | TelephonyManager |
| 1074 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1075 | } |
| 1076 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1077 | + ar.exception); |
| 1078 | } else { |
| 1079 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1080 | } |
| 1081 | } |
| 1082 | notifyRequester(request); |
| 1083 | break; |
| 1084 | } |
| 1085 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1086 | case CMD_ENABLE_VONR: { |
| 1087 | request = (MainThreadRequest) msg.obj; |
| 1088 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1089 | Phone phone = getPhoneFromRequest(request); |
| 1090 | if (phone != null) { |
| 1091 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1092 | request.workSource); |
| 1093 | } else { |
| 1094 | loge("setVoNrEnabled: No phone object"); |
| 1095 | request.result = |
| 1096 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1097 | notifyRequester(request); |
| 1098 | } |
| 1099 | break; |
| 1100 | } |
| 1101 | |
| 1102 | case EVENT_ENABLE_VONR_DONE: { |
| 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
| 1105 | if (ar.exception == null) { |
| 1106 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1107 | } else { |
| 1108 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1109 | if (ar.exception instanceof CommandException) { |
| 1110 | CommandException.Error error = |
| 1111 | ((CommandException) (ar.exception)).getCommandError(); |
| 1112 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1113 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1114 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1115 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1116 | } else { |
| 1117 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1118 | } |
| 1119 | loge("setVoNrEnabled" + ": CommandException: " |
| 1120 | + ar.exception); |
| 1121 | } else { |
| 1122 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1123 | } |
| 1124 | } |
| 1125 | notifyRequester(request); |
| 1126 | break; |
| 1127 | } |
| 1128 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1129 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1130 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1131 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1132 | request); |
| 1133 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1134 | break; |
| 1135 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1136 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1137 | ar = (AsyncResult) msg.obj; |
| 1138 | request = (MainThreadRequest) ar.userObj; |
| 1139 | if (ar.exception == null && ar.result != null) { |
| 1140 | request.result = ar.result; // Integer |
| 1141 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1142 | // request.result must be set to something non-null |
| 1143 | // for the calling thread to unblock |
| 1144 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1145 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1146 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1147 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1148 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1149 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1150 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1151 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1152 | } |
| 1153 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1154 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1155 | break; |
| 1156 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1157 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1158 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1159 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1160 | request); |
| 1161 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1162 | (Pair<Integer, Long>) request.argument; |
| 1163 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1164 | reasonWithNetworkTypes.first, |
| 1165 | reasonWithNetworkTypes.second, |
| 1166 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1167 | break; |
| 1168 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1169 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1170 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1171 | break; |
| 1172 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1173 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1174 | request = (MainThreadRequest) msg.obj; |
| 1175 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1176 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1177 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1178 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1179 | break; |
| 1180 | |
| 1181 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1182 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1183 | break; |
| 1184 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1185 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1186 | request = (MainThreadRequest) msg.obj; |
| 1187 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1188 | request); |
| 1189 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1190 | break; |
| 1191 | |
| 1192 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1193 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1194 | break; |
| 1195 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1196 | case CMD_PERFORM_NETWORK_SCAN: |
| 1197 | request = (MainThreadRequest) msg.obj; |
| 1198 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1199 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1200 | break; |
| 1201 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1202 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | request = (MainThreadRequest) msg.obj; |
| 1204 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1205 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1206 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1207 | request.argument; |
| 1208 | int callForwardingReason = args.first; |
| 1209 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | } |
| 1212 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | ar = (AsyncResult) msg.obj; |
| 1214 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1215 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1216 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1217 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1220 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1221 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1222 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1223 | // any service for voice call. |
| 1224 | if ((callForwardInfo.serviceClass |
| 1225 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1226 | callForwardingInfo = new CallForwardingInfo( |
| 1227 | callForwardInfo.status |
| 1228 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1229 | callForwardInfo.reason, |
| 1230 | callForwardInfo.number, |
| 1231 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | break; |
| 1233 | } |
| 1234 | } |
| 1235 | // Didn't find a call forward info for voice call. |
| 1236 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1237 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1238 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1240 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | } else { |
| 1242 | if (ar.result == null) { |
| 1243 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1244 | } |
| 1245 | if (ar.exception != null) { |
| 1246 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1247 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1248 | int errorCode = TelephonyManager |
| 1249 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | if (ar.exception instanceof CommandException) { |
| 1251 | CommandException.Error error = |
| 1252 | ((CommandException) (ar.exception)).getCommandError(); |
| 1253 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1254 | errorCode = TelephonyManager |
| 1255 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1257 | errorCode = TelephonyManager |
| 1258 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | } |
| 1260 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1261 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1266 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | request = (MainThreadRequest) msg.obj; |
| 1268 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1272 | request.argument).first; |
| 1273 | request.phone.setCallForwardingOption( |
| 1274 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1275 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | callForwardingInfoToSet.getReason(), |
| 1278 | callForwardingInfoToSet.getNumber(), |
| 1279 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1280 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1283 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | ar = (AsyncResult) msg.obj; |
| 1285 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | Consumer<Integer> callback = |
| 1287 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1288 | request.argument).second; |
| 1289 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1291 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1292 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | if (ar.exception instanceof CommandException) { |
| 1294 | CommandException.Error error = |
| 1295 | ((CommandException) (ar.exception)).getCommandError(); |
| 1296 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1297 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1298 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1300 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1301 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | callback.accept(errorCode); |
| 1305 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1306 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | request = (MainThreadRequest) msg.obj; |
| 1313 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1314 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1315 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | ar = (AsyncResult) msg.obj; |
| 1320 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1321 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1322 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1324 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1325 | // Service Class is a bit mask per 3gpp 27.007. |
| 1326 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1327 | if (callForwardResults.length > 1 |
| 1328 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1329 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1330 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1331 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1332 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1334 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | } |
| 1336 | } else { |
| 1337 | if (ar.result == null) { |
| 1338 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1339 | } |
| 1340 | if (ar.exception != null) { |
| 1341 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1342 | } |
| 1343 | if (ar.exception instanceof CommandException) { |
| 1344 | CommandException.Error error = |
| 1345 | ((CommandException) (ar.exception)).getCommandError(); |
| 1346 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1347 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1349 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1350 | callWaitingStatus = |
| 1351 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1355 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1359 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1360 | request = (MainThreadRequest) msg.obj; |
| 1361 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1362 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1363 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1365 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1366 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1367 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1368 | ar = (AsyncResult) msg.obj; |
| 1369 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1370 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1371 | Consumer<Integer> callback = |
| 1372 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1373 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1375 | if (ar.exception instanceof CommandException) { |
| 1376 | CommandException.Error error = |
| 1377 | ((CommandException) (ar.exception)).getCommandError(); |
| 1378 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1379 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1380 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1381 | callback.accept( |
| 1382 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1383 | } else { |
| 1384 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1385 | } |
| 1386 | } else { |
| 1387 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1388 | } |
| 1389 | } else { |
| 1390 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1391 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1392 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1393 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1394 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1395 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1396 | ar = (AsyncResult) msg.obj; |
| 1397 | request = (MainThreadRequest) ar.userObj; |
| 1398 | CellNetworkScanResult cellScanResult; |
| 1399 | if (ar.exception == null && ar.result != null) { |
| 1400 | cellScanResult = new CellNetworkScanResult( |
| 1401 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1402 | (List<OperatorInfo>) ar.result); |
| 1403 | } else { |
| 1404 | if (ar.result == null) { |
| 1405 | loge("getCellNetworkScanResults: Empty response"); |
| 1406 | } |
| 1407 | if (ar.exception != null) { |
| 1408 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1409 | } |
| 1410 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1411 | if (ar.exception instanceof CommandException) { |
| 1412 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1413 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1414 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1415 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1416 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1417 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1418 | } |
| 1419 | } |
| 1420 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1421 | } |
| 1422 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1423 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1424 | break; |
| 1425 | |
| 1426 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1427 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1428 | ManualNetworkSelectionArgument selArg = |
| 1429 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1430 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1431 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1432 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1433 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | |
| 1436 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1437 | ar = (AsyncResult) msg.obj; |
| 1438 | request = (MainThreadRequest) ar.userObj; |
| 1439 | if (ar.exception == null) { |
| 1440 | request.result = true; |
| 1441 | } else { |
| 1442 | request.result = false; |
| 1443 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1444 | } |
| 1445 | notifyRequester(request); |
| 1446 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1447 | break; |
| 1448 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1449 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1450 | request = (MainThreadRequest) msg.obj; |
| 1451 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1452 | if (defaultPhone != null) { |
| 1453 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1454 | } else { |
| 1455 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1456 | Bundle bundle = new Bundle(); |
| 1457 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1458 | new ModemActivityInfo(0, 0, 0, |
| 1459 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1460 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1461 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1462 | break; |
| 1463 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1464 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1465 | ar = (AsyncResult) msg.obj; |
| 1466 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1467 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1468 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1469 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1470 | if (mLastModemActivityInfo == null) { |
| 1471 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1472 | mLastModemActivitySpecificInfo[0] = |
| 1473 | new ActivityStatsTechSpecificInfo( |
| 1474 | 0, |
| 1475 | 0, |
| 1476 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1477 | 0); |
| 1478 | mLastModemActivityInfo = |
| 1479 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1480 | } |
| 1481 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1482 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1483 | // Update the last modem activity info and the result of the request. |
| 1484 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1485 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1486 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1487 | } else { |
| 1488 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1489 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1490 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1491 | // We don't want to return mLastModemActivityInfo which is updated |
| 1492 | // inside mergeModemActivityInfo() |
| 1493 | ret = new ModemActivityInfo( |
| 1494 | mLastModemActivityInfo.getTimestampMillis(), |
| 1495 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1496 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1497 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1498 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1499 | } else { |
| 1500 | if (ar.result == null) { |
| 1501 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1502 | error = TelephonyManager.ModemActivityInfoException |
| 1503 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1504 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1505 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1506 | error = TelephonyManager.ModemActivityInfoException |
| 1507 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1508 | } else { |
| 1509 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1510 | error = TelephonyManager.ModemActivityInfoException |
| 1511 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1512 | } |
| 1513 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1514 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1515 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1516 | bundle.putParcelable( |
| 1517 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1518 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1519 | } else { |
| 1520 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1521 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1522 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1523 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1524 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1525 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1526 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1527 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1528 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1529 | CarrierRestrictionRules argument = |
| 1530 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1531 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1532 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1533 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1534 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1535 | |
| 1536 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1537 | ar = (AsyncResult) msg.obj; |
| 1538 | request = (MainThreadRequest) ar.userObj; |
| 1539 | if (ar.exception == null && ar.result != null) { |
| 1540 | request.result = ar.result; |
| 1541 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1542 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1543 | if (ar.exception instanceof CommandException) { |
| 1544 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1545 | CommandException.Error error = |
| 1546 | ((CommandException) (ar.exception)).getCommandError(); |
| 1547 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1548 | request.result = |
| 1549 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1550 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1551 | } else { |
| 1552 | loge("setAllowedCarriers: Unknown exception"); |
| 1553 | } |
| 1554 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1555 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1556 | break; |
| 1557 | |
| 1558 | case CMD_GET_ALLOWED_CARRIERS: |
| 1559 | request = (MainThreadRequest) msg.obj; |
| 1560 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1561 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1562 | break; |
| 1563 | |
| 1564 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1565 | ar = (AsyncResult) msg.obj; |
| 1566 | request = (MainThreadRequest) ar.userObj; |
| 1567 | if (ar.exception == null && ar.result != null) { |
| 1568 | request.result = ar.result; |
| 1569 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1570 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1571 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1572 | if (ar.result == null) { |
| 1573 | loge("getAllowedCarriers: Empty response"); |
| 1574 | } else if (ar.exception instanceof CommandException) { |
| 1575 | loge("getAllowedCarriers: CommandException: " + |
| 1576 | ar.exception); |
| 1577 | } else { |
| 1578 | loge("getAllowedCarriers: Unknown exception"); |
| 1579 | } |
| 1580 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1581 | if (request.argument != null) { |
| 1582 | // This is for the implementation of carrierRestrictionStatus. |
| 1583 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1584 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1585 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1586 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1587 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1588 | CarrierRestrictionRules carrierRestrictionRules = |
| 1589 | (CarrierRestrictionRules) ar.result; |
| 1590 | int carrierId = -1; |
| 1591 | try { |
| 1592 | CarrierIdentifier carrierIdentifier = |
| 1593 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1594 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1595 | carrierIdentifier); |
| 1596 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1597 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1598 | } |
| 1599 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1600 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1601 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1602 | lockStatus = TelephonyManager |
| 1603 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1604 | } |
| 1605 | } else { |
| 1606 | Rlog.e(LOG_TAG, |
| 1607 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1608 | } |
| 1609 | callback.accept(lockStatus); |
| 1610 | } else { |
| 1611 | // This is for the implementation of getAllowedCarriers. |
| 1612 | notifyRequester(request); |
| 1613 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1614 | break; |
| 1615 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1616 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1617 | ar = (AsyncResult) msg.obj; |
| 1618 | request = (MainThreadRequest) ar.userObj; |
| 1619 | if (ar.exception == null && ar.result != null) { |
| 1620 | request.result = ar.result; |
| 1621 | } else { |
| 1622 | request.result = new IllegalArgumentException( |
| 1623 | "Failed to retrieve Forbidden Plmns"); |
| 1624 | if (ar.result == null) { |
| 1625 | loge("getForbiddenPlmns: Empty response"); |
| 1626 | } else { |
| 1627 | loge("getForbiddenPlmns: Unknown exception"); |
| 1628 | } |
| 1629 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1630 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1631 | break; |
| 1632 | |
| 1633 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1634 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1635 | uiccPort = getUiccPortFromRequest(request); |
| 1636 | if (uiccPort == null) { |
| 1637 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1638 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1639 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1640 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1641 | break; |
| 1642 | } |
| 1643 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1644 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1645 | if (uiccApp == null) { |
| 1646 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1647 | + appType); |
| 1648 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1649 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1650 | break; |
| 1651 | } else { |
| 1652 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1653 | + " specified type -- " + appType); |
| 1654 | } |
| 1655 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1656 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1657 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1658 | break; |
| 1659 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1660 | case CMD_SWITCH_SLOTS: |
| 1661 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1662 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1663 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1664 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1665 | break; |
| 1666 | |
| 1667 | case EVENT_SWITCH_SLOTS_DONE: |
| 1668 | ar = (AsyncResult) msg.obj; |
| 1669 | request = (MainThreadRequest) ar.userObj; |
| 1670 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1671 | notifyRequester(request); |
| 1672 | break; |
| 1673 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1674 | request = (MainThreadRequest) msg.obj; |
| 1675 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1676 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1677 | break; |
| 1678 | |
| 1679 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1680 | ar = (AsyncResult) msg.obj; |
| 1681 | request = (MainThreadRequest) ar.userObj; |
| 1682 | if (ar.exception != null) { |
| 1683 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1684 | } else { |
| 1685 | int mode = ((int[]) ar.result)[0]; |
| 1686 | if (mode == 0) { |
| 1687 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1688 | } else { |
| 1689 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1690 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1691 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1692 | notifyRequester(request); |
| 1693 | break; |
| 1694 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1695 | request = (MainThreadRequest) msg.obj; |
| 1696 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1697 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1698 | break; |
| 1699 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1700 | ar = (AsyncResult) msg.obj; |
| 1701 | request = (MainThreadRequest) ar.userObj; |
| 1702 | if (ar.exception != null) { |
| 1703 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1704 | } else { |
| 1705 | request.result = ((int[]) ar.result)[0]; |
| 1706 | } |
| 1707 | notifyRequester(request); |
| 1708 | break; |
| 1709 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1710 | request = (MainThreadRequest) msg.obj; |
| 1711 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1712 | int mode = (int) request.argument; |
| 1713 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1714 | break; |
| 1715 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1716 | ar = (AsyncResult) msg.obj; |
| 1717 | request = (MainThreadRequest) ar.userObj; |
| 1718 | request.result = ar.exception == null; |
| 1719 | notifyRequester(request); |
| 1720 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1721 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1722 | request = (MainThreadRequest) msg.obj; |
| 1723 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1724 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1725 | break; |
| 1726 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1727 | ar = (AsyncResult) msg.obj; |
| 1728 | request = (MainThreadRequest) ar.userObj; |
| 1729 | if (ar.exception != null) { |
| 1730 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1731 | } else { |
| 1732 | request.result = ((int[]) ar.result)[0]; |
| 1733 | } |
| 1734 | notifyRequester(request); |
| 1735 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1736 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1737 | request = (MainThreadRequest) msg.obj; |
| 1738 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1739 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1740 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1741 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1742 | break; |
| 1743 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1744 | ar = (AsyncResult) msg.obj; |
| 1745 | request = (MainThreadRequest) ar.userObj; |
| 1746 | request.result = ar.exception == null; |
| 1747 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1748 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1749 | case CMD_GET_ALL_CELL_INFO: |
| 1750 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1751 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1752 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1753 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1754 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1755 | ar = (AsyncResult) msg.obj; |
| 1756 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1757 | // If a timeout occurs, the response will be null |
| 1758 | request.result = (ar.exception == null && ar.result != null) |
| 1759 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1760 | synchronized (request) { |
| 1761 | request.notifyAll(); |
| 1762 | } |
| 1763 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1764 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1765 | request = (MainThreadRequest) msg.obj; |
| 1766 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1767 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1768 | break; |
| 1769 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1770 | ar = (AsyncResult) msg.obj; |
| 1771 | request = (MainThreadRequest) ar.userObj; |
| 1772 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1773 | try { |
| 1774 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1775 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1776 | cb.onError( |
| 1777 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1778 | ar.exception.getClass().getName(), |
| 1779 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1780 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1781 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1782 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1783 | } else { |
| 1784 | // use the result as returned |
| 1785 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1786 | } |
| 1787 | } catch (RemoteException re) { |
| 1788 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1789 | } |
| 1790 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1791 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1792 | request = (MainThreadRequest) msg.obj; |
| 1793 | WorkSource ws = (WorkSource) request.argument; |
| 1794 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1795 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1796 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1797 | } |
| 1798 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1799 | ar = (AsyncResult) msg.obj; |
| 1800 | request = (MainThreadRequest) ar.userObj; |
| 1801 | if (ar.exception == null) { |
| 1802 | request.result = ar.result; |
| 1803 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1804 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1805 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1806 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | synchronized (request) { |
| 1810 | request.notifyAll(); |
| 1811 | } |
| 1812 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1813 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1814 | case CMD_MODEM_REBOOT: |
| 1815 | request = (MainThreadRequest) msg.obj; |
| 1816 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1817 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1818 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1819 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1820 | handleNullReturnEvent(msg, "rebootModem"); |
| 1821 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1822 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1823 | request = (MainThreadRequest) msg.obj; |
| 1824 | boolean enable = (boolean) request.argument; |
| 1825 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1826 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1827 | PhoneConfigurationManager.getInstance() |
| 1828 | .enablePhone(request.phone, enable, onCompleted); |
| 1829 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1830 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1831 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1832 | ar = (AsyncResult) msg.obj; |
| 1833 | request = (MainThreadRequest) ar.userObj; |
| 1834 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1835 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1836 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1837 | if ((boolean) request.result) { |
| 1838 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1839 | updateModemStateMetrics(); |
| 1840 | } else { |
| 1841 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1842 | + ar.exception); |
| 1843 | } |
| 1844 | notifyRequester(request); |
| 1845 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1846 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1847 | case CMD_GET_MODEM_STATUS: |
| 1848 | request = (MainThreadRequest) msg.obj; |
| 1849 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1850 | PhoneConfigurationManager.getInstance() |
| 1851 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1852 | break; |
| 1853 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1854 | ar = (AsyncResult) msg.obj; |
| 1855 | request = (MainThreadRequest) ar.userObj; |
| 1856 | int id = request.phone.getPhoneId(); |
| 1857 | if (ar.exception == null && ar.result != null) { |
| 1858 | request.result = ar.result; |
| 1859 | //update the cache as modem status has changed |
| 1860 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1861 | (boolean) request.result); |
| 1862 | } else { |
| 1863 | // Return true if modem status cannot be retrieved. For most cases, |
| 1864 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1865 | // and disable modem are not supported. Modem is always on. |
| 1866 | // TODO: this should be fixed in R to support a third |
| 1867 | // status UNKNOWN b/131631629 |
| 1868 | request.result = true; |
| 1869 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1870 | + ar.exception); |
| 1871 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1872 | notifyRequester(request); |
| 1873 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1874 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1875 | request = (MainThreadRequest) msg.obj; |
| 1876 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1877 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1878 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1879 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1880 | break; |
| 1881 | } |
| 1882 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1883 | ar = (AsyncResult) msg.obj; |
| 1884 | request = (MainThreadRequest) ar.userObj; |
| 1885 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1886 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1887 | args.second.accept(ar.exception == null); |
| 1888 | notifyRequester(request); |
| 1889 | break; |
| 1890 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1891 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1892 | request = (MainThreadRequest) msg.obj; |
| 1893 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1894 | Phone phone = getPhoneFromRequest(request); |
| 1895 | if (phone != null) { |
| 1896 | phone.getSystemSelectionChannels(onCompleted); |
| 1897 | } else { |
| 1898 | loge("getSystemSelectionChannels: No phone object"); |
| 1899 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1900 | notifyRequester(request); |
| 1901 | } |
| 1902 | break; |
| 1903 | } |
| 1904 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1905 | ar = (AsyncResult) msg.obj; |
| 1906 | request = (MainThreadRequest) ar.userObj; |
| 1907 | if (ar.exception == null && ar.result != null) { |
| 1908 | request.result = ar.result; |
| 1909 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1910 | request.result = new IllegalStateException( |
| 1911 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1912 | if (ar.result == null) { |
| 1913 | loge("getSystemSelectionChannels: Empty response"); |
| 1914 | } else { |
| 1915 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1916 | } |
| 1917 | } |
| 1918 | notifyRequester(request); |
| 1919 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1920 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1921 | ar = (AsyncResult) msg.obj; |
| 1922 | request = (MainThreadRequest) ar.userObj; |
| 1923 | if (ar.exception == null && ar.result != null) { |
| 1924 | request.result = ar.result; |
| 1925 | } else { |
| 1926 | request.result = -1; |
| 1927 | loge("Failed to set Forbidden Plmns"); |
| 1928 | if (ar.result == null) { |
| 1929 | loge("setForbidenPlmns: Empty response"); |
| 1930 | } else if (ar.exception != null) { |
| 1931 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1932 | request.result = -1; |
| 1933 | } else { |
| 1934 | loge("setForbiddenPlmns: Unknown exception"); |
| 1935 | } |
| 1936 | } |
| 1937 | notifyRequester(request); |
| 1938 | break; |
| 1939 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1940 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1941 | uiccPort = getUiccPortFromRequest(request); |
| 1942 | if (uiccPort == null) { |
| 1943 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1944 | request.result = -1; |
| 1945 | notifyRequester(request); |
| 1946 | break; |
| 1947 | } |
| 1948 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1949 | (Pair<Integer, List<String>>) request.argument; |
| 1950 | appType = setFplmnsArgs.first; |
| 1951 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1952 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1953 | if (uiccApp == null) { |
| 1954 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1955 | request.result = -1; |
| 1956 | loge("Failed to get UICC App"); |
| 1957 | notifyRequester(request); |
| 1958 | } else { |
| 1959 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1960 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1961 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1962 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1963 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1964 | case CMD_ERASE_MODEM_CONFIG: |
| 1965 | request = (MainThreadRequest) msg.obj; |
| 1966 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1967 | defaultPhone.eraseModemConfig(onCompleted); |
| 1968 | break; |
| 1969 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1970 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1971 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1972 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1973 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1974 | request = (MainThreadRequest) msg.obj; |
| 1975 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1976 | notifyRequester(request); |
| 1977 | break; |
| 1978 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1979 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1980 | request = (MainThreadRequest) msg.obj; |
| 1981 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1982 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1983 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1984 | changed.first, changed.second, onCompleted); |
| 1985 | break; |
| 1986 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1987 | ar = (AsyncResult) msg.obj; |
| 1988 | request = (MainThreadRequest) ar.userObj; |
| 1989 | if (ar.exception == null) { |
| 1990 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1991 | // If the operation is successful, update the PIN storage |
| 1992 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1993 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1994 | UiccController.getInstance().getPinStorage() |
| 1995 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1996 | } else { |
| 1997 | request.result = msg.arg1; |
| 1998 | } |
| 1999 | notifyRequester(request); |
| 2000 | break; |
| 2001 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2002 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2003 | request = (MainThreadRequest) msg.obj; |
| 2004 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2005 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2006 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2007 | enabled.first, enabled.second, onCompleted); |
| 2008 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2009 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2010 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2011 | ar = (AsyncResult) msg.obj; |
| 2012 | request = (MainThreadRequest) ar.userObj; |
| 2013 | if (ar.exception == null) { |
| 2014 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2015 | // If the operation is successful, update the PIN storage |
| 2016 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2017 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2018 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2019 | UiccController.getInstance().getPinStorage() |
| 2020 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2021 | } else { |
| 2022 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2023 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2024 | } else { |
| 2025 | request.result = msg.arg1; |
| 2026 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2027 | |
| 2028 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2029 | notifyRequester(request); |
| 2030 | break; |
| 2031 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2032 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2033 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2034 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2035 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2036 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2037 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2038 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2039 | |
| 2040 | case CMD_SET_DATA_THROTTLING: { |
| 2041 | request = (MainThreadRequest) msg.obj; |
| 2042 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2043 | DataThrottlingRequest dataThrottlingRequest = |
| 2044 | (DataThrottlingRequest) request.argument; |
| 2045 | Phone phone = getPhoneFromRequest(request); |
| 2046 | if (phone != null) { |
| 2047 | phone.setDataThrottling(onCompleted, |
| 2048 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2049 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2050 | } else { |
| 2051 | loge("setDataThrottling: No phone object"); |
| 2052 | request.result = |
| 2053 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2054 | notifyRequester(request); |
| 2055 | } |
| 2056 | |
| 2057 | break; |
| 2058 | } |
| 2059 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2060 | ar = (AsyncResult) msg.obj; |
| 2061 | request = (MainThreadRequest) ar.userObj; |
| 2062 | |
| 2063 | if (ar.exception == null) { |
| 2064 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2065 | } else if (ar.exception instanceof CommandException) { |
| 2066 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2067 | CommandException.Error error = |
| 2068 | ((CommandException) (ar.exception)).getCommandError(); |
| 2069 | |
| 2070 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2071 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2072 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2073 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2074 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2075 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2076 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2077 | } else { |
| 2078 | request.result = |
| 2079 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2080 | } |
| 2081 | } else { |
| 2082 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2083 | } |
| 2084 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2085 | notifyRequester(request); |
| 2086 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2087 | |
| 2088 | case CMD_SET_SIM_POWER: { |
| 2089 | request = (MainThreadRequest) msg.obj; |
| 2090 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2091 | request = (MainThreadRequest) msg.obj; |
| 2092 | int stateToSet = |
| 2093 | ((Pair<Integer, IIntegerConsumer>) |
| 2094 | request.argument).first; |
| 2095 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2096 | break; |
| 2097 | } |
| 2098 | case EVENT_SET_SIM_POWER_DONE: { |
| 2099 | ar = (AsyncResult) msg.obj; |
| 2100 | request = (MainThreadRequest) ar.userObj; |
| 2101 | IIntegerConsumer callback = |
| 2102 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2103 | if (ar.exception != null) { |
| 2104 | loge("setSimPower exception: " + ar.exception); |
| 2105 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2106 | .RESULT_ERROR_UNKNOWN; |
| 2107 | if (ar.exception instanceof CommandException) { |
| 2108 | CommandException.Error error = |
| 2109 | ((CommandException) (ar.exception)).getCommandError(); |
| 2110 | if (error == CommandException.Error.SIM_ERR) { |
| 2111 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2112 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2113 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2114 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2115 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2116 | } else { |
| 2117 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2118 | } |
| 2119 | } |
| 2120 | try { |
| 2121 | callback.accept(errorCode); |
| 2122 | } catch (RemoteException e) { |
| 2123 | // Ignore if the remote process is no longer available to call back. |
| 2124 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2125 | } |
| 2126 | } else { |
| 2127 | try { |
| 2128 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2129 | } catch (RemoteException e) { |
| 2130 | // Ignore if the remote process is no longer available to call back. |
| 2131 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2132 | } |
| 2133 | } |
| 2134 | break; |
| 2135 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2136 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2137 | request = (MainThreadRequest) msg.obj; |
| 2138 | |
| 2139 | final Phone phone = getPhoneFromRequest(request); |
| 2140 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2141 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2142 | notifyRequester(request); |
| 2143 | break; |
| 2144 | } |
| 2145 | |
| 2146 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2147 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2148 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2149 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2150 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2151 | request.subId, pair.first /*callingUid*/, |
| 2152 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2153 | break; |
| 2154 | } |
| 2155 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2156 | ar = (AsyncResult) msg.obj; |
| 2157 | request = (MainThreadRequest) ar.userObj; |
| 2158 | // request.result will be the exception of ar if present, true otherwise. |
| 2159 | // Be cautious not to leave result null which will wait() forever |
| 2160 | request.result = ar.exception != null ? ar.exception : true; |
| 2161 | notifyRequester(request); |
| 2162 | break; |
| 2163 | } |
| 2164 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2165 | request = (MainThreadRequest) msg.obj; |
| 2166 | |
| 2167 | Phone phone = getPhoneFromRequest(request); |
| 2168 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2169 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2170 | notifyRequester(request); |
| 2171 | break; |
| 2172 | } |
| 2173 | |
| 2174 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2175 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2176 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2177 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2178 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2179 | request.subId, pair.first /*callingUid*/, |
| 2180 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2181 | break; |
| 2182 | } |
| 2183 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2184 | ar = (AsyncResult) msg.obj; |
| 2185 | request = (MainThreadRequest) ar.userObj; |
| 2186 | request.result = ar.exception != null ? ar.exception : true; |
| 2187 | notifyRequester(request); |
| 2188 | break; |
| 2189 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2190 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2191 | case CMD_GET_SLICING_CONFIG: { |
| 2192 | request = (MainThreadRequest) msg.obj; |
| 2193 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2194 | request.phone.getSlicingConfig(onCompleted); |
| 2195 | break; |
| 2196 | } |
| 2197 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2198 | ar = (AsyncResult) msg.obj; |
| 2199 | request = (MainThreadRequest) ar.userObj; |
| 2200 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2201 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2202 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2203 | Bundle bundle = new Bundle(); |
| 2204 | int resultCode = 0; |
| 2205 | if (ar.exception != null) { |
| 2206 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2207 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2208 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2209 | } else if (ar.result == null) { |
| 2210 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2211 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2212 | } else { |
| 2213 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2214 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2215 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2219 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2220 | } |
| 2221 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2222 | result.send(resultCode, bundle); |
| 2223 | notifyRequester(request); |
| 2224 | break; |
| 2225 | } |
| 2226 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2227 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2228 | request = (MainThreadRequest) msg.obj; |
| 2229 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2230 | PurchasePremiumCapabilityArgument arg = |
| 2231 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2232 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2233 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2234 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2235 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2236 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2237 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2238 | ar = (AsyncResult) msg.obj; |
| 2239 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2240 | PurchasePremiumCapabilityArgument arg = |
| 2241 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2242 | try { |
| 2243 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2244 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2245 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2246 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2247 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2248 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2249 | } catch (RemoteException e) { |
| 2250 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2251 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2252 | + " failed: " + e; |
| 2253 | if (DBG) log(logStr); |
| 2254 | AnomalyReporter.reportAnomaly( |
| 2255 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2256 | } |
| 2257 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2258 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2259 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2260 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2261 | request = (MainThreadRequest) msg.obj; |
| 2262 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2263 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2264 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2265 | notifyRequester(request); |
| 2266 | break; |
| 2267 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2268 | default: |
| 2269 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2270 | break; |
| 2271 | } |
| 2272 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2273 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2274 | private void notifyRequester(MainThreadRequest request) { |
| 2275 | synchronized (request) { |
| 2276 | request.notifyAll(); |
| 2277 | } |
| 2278 | } |
| 2279 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2280 | private void handleNullReturnEvent(Message msg, String command) { |
| 2281 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2282 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2283 | if (ar.exception == null) { |
| 2284 | request.result = true; |
| 2285 | } else { |
| 2286 | request.result = false; |
| 2287 | if (ar.exception instanceof CommandException) { |
| 2288 | loge(command + ": CommandException: " + ar.exception); |
| 2289 | } else { |
| 2290 | loge(command + ": Unknown exception"); |
| 2291 | } |
| 2292 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2293 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2294 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | /** |
| 2298 | * Posts the specified command to be executed on the main thread, |
| 2299 | * waits for the request to complete, and returns the result. |
| 2300 | * @see #sendRequestAsync |
| 2301 | */ |
| 2302 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2303 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2304 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | /** |
| 2308 | * Posts the specified command to be executed on the main thread, |
| 2309 | * waits for the request to complete, and returns the result. |
| 2310 | * @see #sendRequestAsync |
| 2311 | */ |
| 2312 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2313 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2314 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | /** |
| 2318 | * Posts the specified command to be executed on the main thread, |
| 2319 | * waits for the request to complete, and returns the result. |
| 2320 | * @see #sendRequestAsync |
| 2321 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2322 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2323 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2324 | } |
| 2325 | |
| 2326 | /** |
| 2327 | * Posts the specified command to be executed on the main thread, |
| 2328 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2329 | * if not timeout or null otherwise. |
| 2330 | * @see #sendRequestAsync |
| 2331 | */ |
| 2332 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2333 | long timeoutInMs) { |
| 2334 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | /** |
| 2338 | * Posts the specified command to be executed on the main thread, |
| 2339 | * waits for the request to complete, and returns the result. |
| 2340 | * @see #sendRequestAsync |
| 2341 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2342 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2343 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | /** |
| 2347 | * Posts the specified command to be executed on the main thread, |
| 2348 | * waits for the request to complete, and returns the result. |
| 2349 | * @see #sendRequestAsync |
| 2350 | */ |
| 2351 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2352 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2353 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2357 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2358 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2359 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2360 | * @see #sendRequestAsync |
| 2361 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2362 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2363 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2365 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2366 | } |
| 2367 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2368 | MainThreadRequest request = null; |
| 2369 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2370 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2371 | } else if (phone != null) { |
| 2372 | request = new MainThreadRequest(argument, phone, workSource); |
| 2373 | } else { |
| 2374 | request = new MainThreadRequest(argument, subId, workSource); |
| 2375 | } |
| 2376 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2378 | msg.sendToTarget(); |
| 2379 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2382 | if (timeoutInMs >= 0) { |
| 2383 | // Wait for at least timeoutInMs before returning null request result |
| 2384 | long now = SystemClock.elapsedRealtime(); |
| 2385 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2386 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2387 | try { |
| 2388 | request.wait(deadline - now); |
| 2389 | } catch (InterruptedException e) { |
| 2390 | // Do nothing, go back and check if request is completed or timeout |
| 2391 | } finally { |
| 2392 | now = SystemClock.elapsedRealtime(); |
| 2393 | } |
| 2394 | } |
| 2395 | } else { |
| 2396 | // Wait for the request to complete |
| 2397 | while (request.result == null) { |
| 2398 | try { |
| 2399 | request.wait(); |
| 2400 | } catch (InterruptedException e) { |
| 2401 | // Do nothing, go back and wait until the request is complete |
| 2402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2406 | if (request.result == null) { |
| 2407 | Log.wtf(LOG_TAG, |
| 2408 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2409 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | return request.result; |
| 2411 | } |
| 2412 | |
| 2413 | /** |
| 2414 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2415 | * Posts the specified command to be executed on the main thread, and |
| 2416 | * returns immediately. |
| 2417 | * @see #sendRequest |
| 2418 | */ |
| 2419 | private void sendRequestAsync(int command) { |
| 2420 | mMainThreadHandler.sendEmptyMessage(command); |
| 2421 | } |
| 2422 | |
| 2423 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2424 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2425 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2426 | */ |
| 2427 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2428 | sendRequestAsync(command, argument, null, null); |
| 2429 | } |
| 2430 | |
| 2431 | /** |
| 2432 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2433 | * @see {@link #sendRequest(int,Object)} |
| 2434 | */ |
| 2435 | private void sendRequestAsync( |
| 2436 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2437 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2438 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2439 | msg.sendToTarget(); |
| 2440 | } |
| 2441 | |
| 2442 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2444 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2445 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2446 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2447 | synchronized (PhoneInterfaceManager.class) { |
| 2448 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2449 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2450 | } else { |
| 2451 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2452 | } |
| 2453 | return sInstance; |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2458 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2460 | mFeatureFlags = featureFlags; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2461 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2462 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2463 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2464 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2465 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2466 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2467 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2468 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2469 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2470 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2471 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2472 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 2473 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2474 | getDefaultPhone().getContext(), featureFlags); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2475 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2477 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2480 | @VisibleForTesting |
| 2481 | public SharedPreferences getSharedPreferences() { |
| 2482 | return mTelephonySharedPreferences; |
| 2483 | } |
| 2484 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2485 | /** |
| 2486 | * Get the default phone for this device. |
| 2487 | */ |
| 2488 | @VisibleForTesting |
| 2489 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2490 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2491 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2492 | } |
| 2493 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2494 | private void publish() { |
| 2495 | if (DBG) log("publish: " + this); |
| 2496 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2497 | TelephonyFrameworkInitializer |
| 2498 | .getTelephonyServiceManager() |
| 2499 | .getTelephonyServiceRegisterer() |
| 2500 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2503 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2504 | if (request.phone != null) { |
| 2505 | return request.phone; |
| 2506 | } else { |
| 2507 | return getPhoneFromSubId(request.subId); |
| 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | private Phone getPhoneFromSubId(int subId) { |
| 2512 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2513 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2516 | /** |
| 2517 | * Get phone object associated with a subscription. |
| 2518 | * Return default phone if phone object associated with subscription is null |
| 2519 | * @param subId - subscriptionId |
| 2520 | * @return phone object associated with a subscription or default phone if null. |
| 2521 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2522 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2523 | Phone phone = getPhoneFromSubId(subId); |
| 2524 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2525 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2526 | phone = getDefaultPhone(); |
| 2527 | } |
| 2528 | return phone; |
| 2529 | } |
| 2530 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2531 | @Nullable |
| 2532 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2533 | Phone phone = getPhoneFromRequest(request); |
| 2534 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2535 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2536 | } |
| 2537 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2538 | /** |
| 2539 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2540 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2541 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2542 | * @return The Phone associated the sub Id |
| 2543 | */ |
| 2544 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2545 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2547 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2548 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2549 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2550 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2551 | } |
| 2552 | |
| 2553 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2554 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2555 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2558 | private boolean isImsAvailableOnDevice() { |
| 2559 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2560 | if (pm == null) { |
| 2561 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2562 | // so do not throw error and allow. |
| 2563 | return true; |
| 2564 | } |
| 2565 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2566 | } |
| 2567 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2569 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2570 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2571 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2572 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2575 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | if (DBG) log("dial: " + number); |
| 2577 | // No permission check needed here: This is just a wrapper around the |
| 2578 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2579 | // the UI before it does anything. |
| 2580 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2581 | final long identity = Binder.clearCallingIdentity(); |
| 2582 | try { |
| 2583 | String url = createTelUrl(number); |
| 2584 | if (url == null) { |
| 2585 | return; |
| 2586 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2587 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2589 | PhoneConstants.State state = mCM.getState(subId); |
| 2590 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2591 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2592 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2593 | mApp.startActivity(intent); |
| 2594 | } |
| 2595 | } finally { |
| 2596 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2601 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2604 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | if (DBG) log("call: " + number); |
| 2606 | |
| 2607 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2608 | // need to do a permission check since we're calling startActivity() |
| 2609 | // from the context of the phone app. |
| 2610 | enforceCallPermission(); |
| 2611 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2612 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | != AppOpsManager.MODE_ALLOWED) { |
| 2614 | return; |
| 2615 | } |
| 2616 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2617 | enforceTelephonyFeatureWithException(callingPackage, |
| 2618 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | final long identity = Binder.clearCallingIdentity(); |
| 2621 | try { |
| 2622 | String url = createTelUrl(number); |
| 2623 | if (url == null) { |
| 2624 | return; |
| 2625 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | boolean isValid = false; |
| 2628 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2629 | if (slist != null) { |
| 2630 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2631 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2632 | isValid = true; |
| 2633 | break; |
| 2634 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2635 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2636 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2637 | if (!isValid) { |
| 2638 | return; |
| 2639 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2640 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2642 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2643 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2644 | mApp.startActivity(intent); |
| 2645 | } finally { |
| 2646 | Binder.restoreCallingIdentity(identity); |
| 2647 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2650 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2651 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2652 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2653 | } |
| 2654 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2655 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2656 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2657 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2658 | } |
| 2659 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2660 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2663 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2664 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2665 | "supplyPinReportResultForSubscriber"); |
| 2666 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | final long identity = Binder.clearCallingIdentity(); |
| 2668 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2669 | Phone phone = getPhone(subId); |
| 2670 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | checkSimPin.start(); |
| 2672 | return checkSimPin.unlockSim(null, pin); |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(identity); |
| 2675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2678 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2681 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2682 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2683 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | final long identity = Binder.clearCallingIdentity(); |
| 2685 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2686 | Phone phone = getPhone(subId); |
| 2687 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | checkSimPuk.start(); |
| 2689 | return checkSimPuk.unlockSim(puk, pin); |
| 2690 | } finally { |
| 2691 | Binder.restoreCallingIdentity(identity); |
| 2692 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2696 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | * a synchronous one. |
| 2698 | */ |
| 2699 | private static class UnlockSim extends Thread { |
| 2700 | |
| 2701 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2702 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | |
| 2704 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2705 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2706 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2707 | |
| 2708 | // For replies from SimCard interface |
| 2709 | private Handler mHandler; |
| 2710 | |
| 2711 | // For async handler to identify request type |
| 2712 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2713 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2714 | UnlockSim(int phoneId, IccCard simCard) { |
| 2715 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | mSimCard = simCard; |
| 2717 | } |
| 2718 | |
| 2719 | @Override |
| 2720 | public void run() { |
| 2721 | Looper.prepare(); |
| 2722 | synchronized (UnlockSim.this) { |
| 2723 | mHandler = new Handler() { |
| 2724 | @Override |
| 2725 | public void handleMessage(Message msg) { |
| 2726 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2727 | switch (msg.what) { |
| 2728 | case SUPPLY_PIN_COMPLETE: |
| 2729 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2730 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2731 | mRetryCount = msg.arg1; |
| 2732 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2733 | CommandException.Error error = null; |
| 2734 | if (ar.exception instanceof CommandException) { |
| 2735 | error = ((CommandException) (ar.exception)) |
| 2736 | .getCommandError(); |
| 2737 | } |
| 2738 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2739 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2740 | } else if (error == CommandException.Error.ABORTED) { |
| 2741 | /* When UiccCardApp dispose, handle message and return |
| 2742 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2743 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2744 | } else { |
| 2745 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2746 | } |
| 2747 | } else { |
| 2748 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2749 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2750 | mDone = true; |
| 2751 | UnlockSim.this.notifyAll(); |
| 2752 | } |
| 2753 | break; |
| 2754 | } |
| 2755 | } |
| 2756 | }; |
| 2757 | UnlockSim.this.notifyAll(); |
| 2758 | } |
| 2759 | Looper.loop(); |
| 2760 | } |
| 2761 | |
| 2762 | /* |
| 2763 | * Use PIN or PUK to unlock SIM card |
| 2764 | * |
| 2765 | * If PUK is null, unlock SIM card with PIN |
| 2766 | * |
| 2767 | * 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] | 2768 | * |
| 2769 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2770 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2772 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2773 | |
| 2774 | while (mHandler == null) { |
| 2775 | try { |
| 2776 | wait(); |
| 2777 | } catch (InterruptedException e) { |
| 2778 | Thread.currentThread().interrupt(); |
| 2779 | } |
| 2780 | } |
| 2781 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2782 | |
| 2783 | if (puk == null) { |
| 2784 | mSimCard.supplyPin(pin, callback); |
| 2785 | } else { |
| 2786 | mSimCard.supplyPuk(puk, pin, callback); |
| 2787 | } |
| 2788 | |
| 2789 | while (!mDone) { |
| 2790 | try { |
| 2791 | Log.d(LOG_TAG, "wait for done"); |
| 2792 | wait(); |
| 2793 | } catch (InterruptedException e) { |
| 2794 | // Restore the interrupted status |
| 2795 | Thread.currentThread().interrupt(); |
| 2796 | } |
| 2797 | } |
| 2798 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2799 | int[] resultArray = new int[2]; |
| 2800 | resultArray[0] = mResult; |
| 2801 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2802 | |
| 2803 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2804 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2805 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2806 | // This instance is no longer reused, so quit its thread's looper. |
| 2807 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2808 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2809 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2810 | } |
| 2811 | } |
| 2812 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2813 | /** |
| 2814 | * This method has been removed due to privacy and stability concerns. |
| 2815 | */ |
| 2816 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2817 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2818 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2819 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2822 | @Override |
| 2823 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2824 | mApp.getSystemService(AppOpsManager.class) |
| 2825 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2826 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2827 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2828 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2829 | // Callers targeting S have no business invoking this method. |
| 2830 | return; |
| 2831 | } |
| 2832 | |
| 2833 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2834 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2835 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2836 | .setCallingPackage(callingPackage) |
| 2837 | .setCallingFeatureId(null) |
| 2838 | .setCallingPid(Binder.getCallingPid()) |
| 2839 | .setCallingUid(Binder.getCallingUid()) |
| 2840 | .setMethod("updateServiceLocation") |
| 2841 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2842 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2843 | .build()); |
| 2844 | // Apps that lack location permission have no business calling this method; |
| 2845 | // however, because no permission was declared in the public API, denials must |
| 2846 | // all be "soft". |
| 2847 | switch (locationResult) { |
| 2848 | case DENIED_HARD: /* fall through */ |
| 2849 | case DENIED_SOFT: |
| 2850 | return; |
| 2851 | } |
| 2852 | |
| 2853 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2854 | final long identity = Binder.clearCallingIdentity(); |
| 2855 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2856 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | } finally { |
| 2858 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2859 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2862 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2863 | @Override |
| 2864 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2865 | return isRadioOnWithFeature(callingPackage, null); |
| 2866 | } |
| 2867 | |
| 2868 | |
| 2869 | @Override |
| 2870 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2871 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2872 | callingFeatureId); |
| 2873 | } |
| 2874 | |
| 2875 | @Deprecated |
| 2876 | @Override |
| 2877 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2878 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2879 | } |
| 2880 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2881 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2882 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2883 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2884 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2885 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2886 | return false; |
| 2887 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2888 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2889 | enforceTelephonyFeatureWithException(callingPackage, |
| 2890 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2891 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2892 | final long identity = Binder.clearCallingIdentity(); |
| 2893 | try { |
| 2894 | return isRadioOnForSubscriber(subId); |
| 2895 | } finally { |
| 2896 | Binder.restoreCallingIdentity(identity); |
| 2897 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | final Phone phone = getPhone(subId); |
| 2904 | if (phone != null) { |
| 2905 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2906 | } else { |
| 2907 | return false; |
| 2908 | } |
| 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2911 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2915 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2916 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2917 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2918 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2919 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2920 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2921 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2922 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2923 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | final long identity = Binder.clearCallingIdentity(); |
| 2925 | try { |
| 2926 | final Phone phone = getPhone(subId); |
| 2927 | if (phone != null) { |
| 2928 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2929 | } |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2932 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2936 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2937 | } |
| 2938 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2939 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2940 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2941 | |
| 2942 | final long identity = Binder.clearCallingIdentity(); |
| 2943 | try { |
| 2944 | final Phone phone = getPhone(subId); |
| 2945 | if (phone == null) { |
| 2946 | return false; |
| 2947 | } |
| 2948 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2949 | toggleRadioOnOffForSubscriber(subId); |
| 2950 | } |
| 2951 | return true; |
| 2952 | } finally { |
| 2953 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2954 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2955 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2956 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2957 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2958 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2959 | |
| 2960 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2961 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 2962 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2963 | /* |
| 2964 | * If any of the Radios are available, it will need to be |
| 2965 | * shutdown. So return true if any Radio is available. |
| 2966 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | final long identity = Binder.clearCallingIdentity(); |
| 2968 | try { |
| 2969 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2970 | Phone phone = PhoneFactory.getPhone(i); |
| 2971 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2972 | } |
| 2973 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2974 | return false; |
| 2975 | } finally { |
| 2976 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2977 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2980 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2981 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2982 | enforceModifyPermission(); |
| 2983 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2984 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2985 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 2986 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2987 | final long identity = Binder.clearCallingIdentity(); |
| 2988 | try { |
| 2989 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2990 | logv("Shutting down Phone " + i); |
| 2991 | shutdownRadioUsingPhoneId(i); |
| 2992 | } |
| 2993 | } finally { |
| 2994 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2999 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3000 | if (phone != null && phone.isRadioAvailable()) { |
| 3001 | phone.shutdownRadio(); |
| 3002 | } |
| 3003 | } |
| 3004 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3005 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3006 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3007 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3008 | if (!turnOn) { |
| 3009 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3010 | } |
| 3011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 | final long identity = Binder.clearCallingIdentity(); |
| 3013 | try { |
| 3014 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3015 | if (defaultPhone != null) { |
| 3016 | defaultPhone.setRadioPower(turnOn); |
| 3017 | return true; |
| 3018 | } else { |
| 3019 | loge("There's no default phone."); |
| 3020 | return false; |
| 3021 | } |
| 3022 | } finally { |
| 3023 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3024 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3027 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3028 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3030 | if (!turnOn) { |
| 3031 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3032 | + ",callingPackage=" + getCurrentPackageName()); |
| 3033 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
| 3036 | final Phone phone = getPhone(subId); |
| 3037 | if (phone != null) { |
| 3038 | phone.setRadioPower(turnOn); |
| 3039 | return true; |
| 3040 | } else { |
| 3041 | return false; |
| 3042 | } |
| 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3045 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3048 | /** |
| 3049 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3050 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3051 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3052 | * powering it off, and these radio off votes will be cleared. |
| 3053 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3054 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3055 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3056 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3057 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3058 | * check its vote. |
| 3059 | * |
| 3060 | * @param subId The subscription ID. |
| 3061 | * @param reason The reason for powering off radio. |
| 3062 | * @return true on success and false on failure. |
| 3063 | */ |
| 3064 | public boolean requestRadioPowerOffForReason(int subId, |
| 3065 | @TelephonyManager.RadioPowerReason int reason) { |
| 3066 | enforceModifyPermission(); |
| 3067 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3068 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3069 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3070 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3071 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3072 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3073 | final long identity = Binder.clearCallingIdentity(); |
| 3074 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3075 | boolean result = false; |
| 3076 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3077 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3078 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3079 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3080 | if (!result) { |
| 3081 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3082 | } |
| 3083 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3084 | } finally { |
| 3085 | Binder.restoreCallingIdentity(identity); |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | /** |
| 3090 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3091 | * {@link requestRadioPowerOffForReason}. |
| 3092 | * |
| 3093 | * @param subId The subscription ID. |
| 3094 | * @param reason The reason for powering off radio. |
| 3095 | * @return true on success and false on failure. |
| 3096 | */ |
| 3097 | public boolean clearRadioPowerOffForReason(int subId, |
| 3098 | @TelephonyManager.RadioPowerReason int reason) { |
| 3099 | enforceModifyPermission(); |
| 3100 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3101 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3102 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3103 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3104 | final long identity = Binder.clearCallingIdentity(); |
| 3105 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3106 | boolean result = false; |
| 3107 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3108 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3109 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3110 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3111 | if (!result) { |
| 3112 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3113 | } |
| 3114 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | /** |
| 3121 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3122 | * |
| 3123 | * @param subId The subscription ID. |
| 3124 | * @param callingPackage The package making the call. |
| 3125 | * @param callingFeatureId The feature in the package. |
| 3126 | * @return List of reasons for powering off radio. |
| 3127 | */ |
| 3128 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3129 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3130 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3131 | enforceTelephonyFeatureWithException(callingPackage, |
| 3132 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3133 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3134 | final long identity = Binder.clearCallingIdentity(); |
| 3135 | List result = new ArrayList(); |
| 3136 | try { |
| 3137 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3138 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3139 | return result; |
| 3140 | } |
| 3141 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3142 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3143 | if (phone != null) { |
| 3144 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3145 | } else { |
| 3146 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3147 | } |
| 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
| 3150 | } |
| 3151 | return result; |
| 3152 | } |
| 3153 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3154 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3156 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3157 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3159 | enforceTelephonyFeatureWithException(callingPackage, |
| 3160 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3161 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3162 | final long identity = Binder.clearCallingIdentity(); |
| 3163 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3164 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3165 | final Phone phone = getPhone(subId); |
| 3166 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3167 | phone.getDataSettingsManager().setDataEnabled( |
| 3168 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3169 | return true; |
| 3170 | } else { |
| 3171 | return false; |
| 3172 | } |
| 3173 | } finally { |
| 3174 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3175 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3176 | } |
| 3177 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3178 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3179 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3180 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3181 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3182 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3183 | enforceTelephonyFeatureWithException(callingPackage, |
| 3184 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3185 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3186 | final long identity = Binder.clearCallingIdentity(); |
| 3187 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3188 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | final Phone phone = getPhone(subId); |
| 3190 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3191 | phone.getDataSettingsManager().setDataEnabled( |
| 3192 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3193 | return true; |
| 3194 | } else { |
| 3195 | return false; |
| 3196 | } |
| 3197 | } finally { |
| 3198 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3199 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | } |
| 3201 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3202 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3203 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3204 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3205 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3206 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3207 | final long identity = Binder.clearCallingIdentity(); |
| 3208 | try { |
| 3209 | final Phone phone = getPhone(subId); |
| 3210 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3211 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3212 | } else { |
| 3213 | return false; |
| 3214 | } |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3217 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3221 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3224 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3225 | enforceCallPermission(); |
| 3226 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3227 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3228 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3229 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | final long identity = Binder.clearCallingIdentity(); |
| 3231 | try { |
| 3232 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3233 | return; |
| 3234 | } |
| 3235 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3236 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3237 | } finally { |
| 3238 | Binder.restoreCallingIdentity(identity); |
| 3239 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3240 | }; |
| 3241 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3242 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3243 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3244 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3245 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3246 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3247 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | final long identity = Binder.clearCallingIdentity(); |
| 3249 | try { |
| 3250 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3251 | return false; |
| 3252 | } |
| 3253 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3254 | } finally { |
| 3255 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3256 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3259 | /** |
| 3260 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3261 | * tag on getCallState Binder call. |
| 3262 | */ |
| 3263 | @Deprecated |
| 3264 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3265 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3266 | if (CompatChanges.isChangeEnabled( |
| 3267 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3268 | Binder.getCallingUid())) { |
| 3269 | // Do not allow this API to be called on API version 31+, it should only be |
| 3270 | // called on old apps using this Binder call directly. |
| 3271 | throw new SecurityException("This method can only be used for applications " |
| 3272 | + "targeting API version 30 or less."); |
| 3273 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | final long identity = Binder.clearCallingIdentity(); |
| 3275 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3276 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3277 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3278 | } finally { |
| 3279 | Binder.restoreCallingIdentity(identity); |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | @Override |
| 3284 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3285 | if (CompatChanges.isChangeEnabled( |
| 3286 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3287 | Binder.getCallingUid())) { |
| 3288 | // Check READ_PHONE_STATE for API version 31+ |
| 3289 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3290 | featureId, "getCallStateForSubscription")) { |
| 3291 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3292 | + "targeting API level 31+."); |
| 3293 | } |
| 3294 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3295 | |
| 3296 | enforceTelephonyFeatureWithException(callingPackage, |
| 3297 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3298 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3299 | final long identity = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3302 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3303 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3304 | } finally { |
| 3305 | Binder.restoreCallingIdentity(identity); |
| 3306 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3309 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3310 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3311 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | @Override |
| 3315 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3316 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3317 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3319 | final long identity = Binder.clearCallingIdentity(); |
| 3320 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3321 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3322 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3323 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3324 | } else { |
| 3325 | return PhoneConstantConversions.convertDataState( |
| 3326 | PhoneConstants.DataState.DISCONNECTED); |
| 3327 | } |
| 3328 | } finally { |
| 3329 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3333 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3334 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3335 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3339 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3340 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3341 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3342 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3345 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3346 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3347 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3348 | } else { |
| 3349 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3350 | } |
| 3351 | } finally { |
| 3352 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3353 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3357 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3358 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3359 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3360 | |
| 3361 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3362 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3363 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3364 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3365 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3366 | .setCallingPid(Binder.getCallingPid()) |
| 3367 | .setCallingUid(Binder.getCallingUid()) |
| 3368 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3369 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3370 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3371 | .build()); |
| 3372 | switch (locationResult) { |
| 3373 | case DENIED_HARD: |
| 3374 | throw new SecurityException("Not allowed to access cell location"); |
| 3375 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3376 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3377 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3380 | enforceTelephonyFeatureWithException(callingPackage, |
| 3381 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3382 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3383 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3384 | final long identity = Binder.clearCallingIdentity(); |
| 3385 | try { |
| 3386 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3387 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3388 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(identity); |
| 3391 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3394 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3395 | public String getNetworkCountryIsoForPhone(int phoneId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3396 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3397 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3398 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3399 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3400 | // registered cell info, so return a NULL country instead. |
| 3401 | final long identity = Binder.clearCallingIdentity(); |
| 3402 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3403 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3404 | // Get default phone in this case. |
| 3405 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3406 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3407 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3408 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3409 | if (phone == null) return ""; |
| 3410 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3411 | if (sst == null) return ""; |
| 3412 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3413 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3414 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3415 | } finally { |
| 3416 | Binder.restoreCallingIdentity(identity); |
| 3417 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3418 | } |
| 3419 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3420 | /** |
| 3421 | * This method was removed due to potential issues caused by performing partial |
| 3422 | * updates of service state, and lack of a credible use case. |
| 3423 | * |
| 3424 | * This has the ability to break the telephony implementation by disabling notification of |
| 3425 | * changes in device connectivity. DO NOT USE THIS! |
| 3426 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3427 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3428 | public void enableLocationUpdates() { |
| 3429 | mApp.enforceCallingOrSelfPermission( |
| 3430 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3433 | /** |
| 3434 | * This method was removed due to potential issues caused by performing partial |
| 3435 | * updates of service state, and lack of a credible use case. |
| 3436 | * |
| 3437 | * This has the ability to break the telephony implementation by disabling notification of |
| 3438 | * changes in device connectivity. DO NOT USE THIS! |
| 3439 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3440 | @Override |
| 3441 | public void disableLocationUpdates() { |
| 3442 | mApp.enforceCallingOrSelfPermission( |
| 3443 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | @Override |
| 3447 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3448 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3449 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3450 | try { |
| 3451 | mApp.getSystemService(AppOpsManager.class) |
| 3452 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3453 | } catch (SecurityException e) { |
| 3454 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3455 | throw e; |
| 3456 | } |
| 3457 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3458 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3459 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3460 | throw new SecurityException( |
| 3461 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3462 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3463 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3464 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3465 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3466 | return null; |
| 3467 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3468 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3469 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3470 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3471 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3472 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3473 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3474 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3475 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3476 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3477 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3478 | for (CellInfo ci : info) { |
| 3479 | if (ci instanceof CellInfoGsm) { |
| 3480 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3481 | } else if (ci instanceof CellInfoWcdma) { |
| 3482 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3484 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3485 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3488 | private List<CellInfo> getCachedCellInfo() { |
| 3489 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3490 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3491 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3492 | if (info != null) cellInfos.addAll(info); |
| 3493 | } |
| 3494 | return cellInfos; |
| 3495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3496 | |
| 3497 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3498 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3499 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3500 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3501 | |
| 3502 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3503 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3504 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3505 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3506 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3507 | .setCallingPid(Binder.getCallingPid()) |
| 3508 | .setCallingUid(Binder.getCallingUid()) |
| 3509 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3510 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3511 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3512 | .build()); |
| 3513 | switch (locationResult) { |
| 3514 | case DENIED_HARD: |
| 3515 | throw new SecurityException("Not allowed to access cell info"); |
| 3516 | case DENIED_SOFT: |
| 3517 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3520 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3521 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3522 | return getCachedCellInfo(); |
| 3523 | } |
| 3524 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3525 | enforceTelephonyFeatureWithException(callingPackage, |
| 3526 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3527 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3528 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3529 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3533 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3534 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3535 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | if (info != null) cellInfos.addAll(info); |
| 3537 | } |
| 3538 | return cellInfos; |
| 3539 | } finally { |
| 3540 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3541 | } |
| 3542 | } |
| 3543 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3544 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3545 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3546 | String callingFeatureId) { |
| 3547 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3548 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3552 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3553 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3554 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3555 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3558 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3559 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3560 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3561 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3562 | |
| 3563 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3564 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3565 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3566 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3567 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3568 | .setCallingPid(Binder.getCallingPid()) |
| 3569 | .setCallingUid(Binder.getCallingUid()) |
| 3570 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3571 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3572 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3573 | .build()); |
| 3574 | switch (locationResult) { |
| 3575 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3576 | if (TelephonyPermissions |
| 3577 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3578 | // Safetynet logging for b/154934934 |
| 3579 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3580 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3581 | throw new SecurityException("Not allowed to access cell info"); |
| 3582 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3583 | if (TelephonyPermissions |
| 3584 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3585 | // Safetynet logging for b/154934934 |
| 3586 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3587 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3588 | try { |
| 3589 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3590 | } catch (RemoteException re) { |
| 3591 | // Drop without consequences |
| 3592 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3593 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3596 | enforceTelephonyFeatureWithException(callingPackage, |
| 3597 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3598 | |
| 3599 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3600 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3601 | |
| 3602 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3603 | } |
| 3604 | |
| 3605 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3606 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3607 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3608 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3609 | |
| 3610 | final long identity = Binder.clearCallingIdentity(); |
| 3611 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3612 | Phone phone = getPhone(subId); |
| 3613 | if (phone == null) { |
| 3614 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3615 | } else { |
| 3616 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3617 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3618 | } finally { |
| 3619 | Binder.restoreCallingIdentity(identity); |
| 3620 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3623 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3624 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3625 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3626 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3627 | return null; |
| 3628 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3629 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3630 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3631 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3632 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3633 | return null; |
| 3634 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3635 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3636 | enforceTelephonyFeatureWithException(callingPackage, |
| 3637 | PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot"); |
| 3638 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3639 | final long identity = Binder.clearCallingIdentity(); |
| 3640 | try { |
| 3641 | return phone.getImei(); |
| 3642 | } finally { |
| 3643 | Binder.restoreCallingIdentity(identity); |
| 3644 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3648 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3649 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3650 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3651 | callingFeatureId, "getPrimaryImei")) { |
| 3652 | throw new SecurityException("Caller does not have permission"); |
| 3653 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3654 | |
| 3655 | enforceTelephonyFeatureWithException(callingPackage, |
| 3656 | PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei"); |
| 3657 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3658 | final long identity = Binder.clearCallingIdentity(); |
| 3659 | try { |
| 3660 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3661 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3662 | return phone.getImei(); |
| 3663 | } |
| 3664 | } |
| 3665 | throw new UnsupportedOperationException("Operation not supported"); |
| 3666 | } finally { |
| 3667 | Binder.restoreCallingIdentity(identity); |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3672 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3673 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3674 | PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot"); |
| 3675 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3676 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3677 | String tac = null; |
| 3678 | if (phone != null) { |
| 3679 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3680 | try { |
| 3681 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3682 | } catch (IndexOutOfBoundsException e) { |
| 3683 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3684 | return null; |
| 3685 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3686 | } |
| 3687 | return tac; |
| 3688 | } |
| 3689 | |
| 3690 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3691 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3692 | try { |
| 3693 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3694 | } catch (SecurityException se) { |
| 3695 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3696 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3697 | + Binder.getCallingUid()); |
| 3698 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3699 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3700 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3701 | return null; |
| 3702 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3703 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3704 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3705 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3706 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3707 | return null; |
| 3708 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3709 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3710 | enforceTelephonyFeatureWithException(callingPackage, |
| 3711 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | return phone.getMeid(); |
| 3716 | } finally { |
| 3717 | Binder.restoreCallingIdentity(identity); |
| 3718 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3722 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3723 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3724 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3725 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3726 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3727 | String manufacturerCode = null; |
| 3728 | if (phone != null) { |
| 3729 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3730 | try { |
| 3731 | manufacturerCode = |
| 3732 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3733 | } catch (IndexOutOfBoundsException e) { |
| 3734 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3735 | return null; |
| 3736 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3737 | } |
| 3738 | return manufacturerCode; |
| 3739 | } |
| 3740 | |
| 3741 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3742 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3743 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3744 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3745 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3746 | return null; |
| 3747 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3748 | int subId = phone.getSubId(); |
| 3749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3750 | mApp, subId, callingPackage, callingFeatureId, |
| 3751 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3752 | return null; |
| 3753 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3754 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3755 | enforceTelephonyFeatureWithException(callingPackage, |
| 3756 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3757 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3758 | final long identity = Binder.clearCallingIdentity(); |
| 3759 | try { |
| 3760 | return phone.getDeviceSvn(); |
| 3761 | } finally { |
| 3762 | Binder.restoreCallingIdentity(identity); |
| 3763 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3764 | } |
| 3765 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3766 | @Override |
| 3767 | public int getSubscriptionCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3768 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3769 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3770 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3771 | final long identity = Binder.clearCallingIdentity(); |
| 3772 | try { |
| 3773 | final Phone phone = getPhone(subId); |
| 3774 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3775 | } finally { |
| 3776 | Binder.restoreCallingIdentity(identity); |
| 3777 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | @Override |
| 3781 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3782 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3783 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3785 | final long identity = Binder.clearCallingIdentity(); |
| 3786 | try { |
| 3787 | final Phone phone = getPhone(subId); |
| 3788 | return phone == null ? null : phone.getCarrierName(); |
| 3789 | } finally { |
| 3790 | Binder.restoreCallingIdentity(identity); |
| 3791 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3794 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3795 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3796 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3797 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3798 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3799 | final long identity = Binder.clearCallingIdentity(); |
| 3800 | try { |
| 3801 | final Phone phone = getPhone(subId); |
| 3802 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3803 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3804 | } finally { |
| 3805 | Binder.restoreCallingIdentity(identity); |
| 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3810 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3811 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3812 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3813 | "getSubscriptionSpecificCarrierName"); |
| 3814 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3815 | final long identity = Binder.clearCallingIdentity(); |
| 3816 | try { |
| 3817 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3818 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3819 | } finally { |
| 3820 | Binder.restoreCallingIdentity(identity); |
| 3821 | } |
| 3822 | } |
| 3823 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3824 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3825 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3826 | if (!isSubscriptionMccMnc) { |
| 3827 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3828 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3829 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3830 | if (phone == null) { |
| 3831 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3832 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3833 | |
| 3834 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3835 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3836 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3837 | final long identity = Binder.clearCallingIdentity(); |
| 3838 | try { |
| 3839 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
| 3842 | } |
| 3843 | } |
| 3844 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3845 | // |
| 3846 | // Internal helper methods. |
| 3847 | // |
| 3848 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3849 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3850 | * Make sure the caller is the calling package itself |
| 3851 | * |
| 3852 | * @throws SecurityException if the caller is not the calling package |
| 3853 | */ |
| 3854 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3855 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3856 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3857 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3858 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3859 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3860 | } catch (PackageManager.NameNotFoundException e) { |
| 3861 | // packageUid is -1 |
| 3862 | } |
| 3863 | if (packageUid != callingUid) { |
| 3864 | throw new SecurityException(message + ": Package " + callingPackage |
| 3865 | + " does not belong to " + callingUid); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3870 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3871 | * |
| 3872 | * @throws SecurityException if the caller does not have the required permission |
| 3873 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3874 | @VisibleForTesting |
| 3875 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3876 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3877 | } |
| 3878 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3879 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3880 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3881 | * |
| 3882 | * @throws SecurityException if the caller does not have the required permission |
| 3883 | */ |
| 3884 | @VisibleForTesting |
| 3885 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3886 | enforceReadPermission(null); |
| 3887 | } |
| 3888 | |
| 3889 | /** |
| 3890 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3891 | * |
| 3892 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3893 | */ |
| 3894 | @VisibleForTesting |
| 3895 | public void enforceReadPermission(String msg) { |
| 3896 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3897 | } |
| 3898 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3899 | private void enforceActiveEmergencySessionPermission() { |
| 3900 | mApp.enforceCallingOrSelfPermission( |
| 3901 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3902 | } |
| 3903 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3904 | /** |
| 3905 | * Make sure the caller has the CALL_PHONE permission. |
| 3906 | * |
| 3907 | * @throws SecurityException if the caller does not have the required permission |
| 3908 | */ |
| 3909 | private void enforceCallPermission() { |
| 3910 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3911 | } |
| 3912 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3913 | private void enforceSettingsPermission() { |
| 3914 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3917 | private void enforceRebootPermission() { |
| 3918 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3919 | } |
| 3920 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3921 | /** |
| 3922 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3923 | * @param message - log message to print. |
| 3924 | * @throws SecurityException if the caller does not have the required permission |
| 3925 | */ |
| 3926 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3927 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3928 | } |
| 3929 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3930 | private String createTelUrl(String number) { |
| 3931 | if (TextUtils.isEmpty(number)) { |
| 3932 | return null; |
| 3933 | } |
| 3934 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3935 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3938 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3939 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3942 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3943 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3946 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3947 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3950 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3951 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3952 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3955 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3956 | public int getActivePhoneTypeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3957 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3958 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 3959 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3960 | final long identity = Binder.clearCallingIdentity(); |
| 3961 | try { |
| 3962 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3963 | if (phone == null) { |
| 3964 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3965 | } else { |
| 3966 | return phone.getPhoneType(); |
| 3967 | } |
| 3968 | } finally { |
| 3969 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3970 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | /** |
| 3974 | * Returns the CDMA ERI icon index to display |
| 3975 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3976 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3977 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3978 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3979 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3982 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3983 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3984 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3986 | mApp, subId, callingPackage, callingFeatureId, |
| 3987 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3988 | return -1; |
| 3989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3990 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3991 | enforceTelephonyFeatureWithException(callingPackage, |
| 3992 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 3993 | "getCdmaEriIconIndexForSubscriber"); |
| 3994 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3995 | final long identity = Binder.clearCallingIdentity(); |
| 3996 | try { |
| 3997 | final Phone phone = getPhone(subId); |
| 3998 | if (phone != null) { |
| 3999 | return phone.getCdmaEriIconIndex(); |
| 4000 | } else { |
| 4001 | return -1; |
| 4002 | } |
| 4003 | } finally { |
| 4004 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4005 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | /** |
| 4009 | * Returns the CDMA ERI icon mode, |
| 4010 | * 0 - ON |
| 4011 | * 1 - FLASHING |
| 4012 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4013 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4014 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4015 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4016 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4019 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4020 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4021 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4022 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4023 | mApp, subId, callingPackage, callingFeatureId, |
| 4024 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4025 | return -1; |
| 4026 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | |
| 4028 | final long identity = Binder.clearCallingIdentity(); |
| 4029 | try { |
| 4030 | final Phone phone = getPhone(subId); |
| 4031 | if (phone != null) { |
| 4032 | return phone.getCdmaEriIconMode(); |
| 4033 | } else { |
| 4034 | return -1; |
| 4035 | } |
| 4036 | } finally { |
| 4037 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4038 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | /** |
| 4042 | * Returns the CDMA ERI text, |
| 4043 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4044 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4045 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4046 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4047 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4050 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4051 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4052 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4053 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4054 | mApp, subId, callingPackage, callingFeatureId, |
| 4055 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4056 | return null; |
| 4057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4058 | |
| 4059 | final long identity = Binder.clearCallingIdentity(); |
| 4060 | try { |
| 4061 | final Phone phone = getPhone(subId); |
| 4062 | if (phone != null) { |
| 4063 | return phone.getCdmaEriText(); |
| 4064 | } else { |
| 4065 | return null; |
| 4066 | } |
| 4067 | } finally { |
| 4068 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4069 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4073 | * Returns the CDMA MDN. |
| 4074 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4075 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4076 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4078 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4079 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4080 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4081 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4083 | final long identity = Binder.clearCallingIdentity(); |
| 4084 | try { |
| 4085 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4086 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4087 | return phone.getLine1Number(); |
| 4088 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4089 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | return null; |
| 4091 | } |
| 4092 | } finally { |
| 4093 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | /** |
| 4098 | * Returns the CDMA MIN. |
| 4099 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4100 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4101 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4102 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4103 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4104 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4105 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4106 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4107 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4108 | final long identity = Binder.clearCallingIdentity(); |
| 4109 | try { |
| 4110 | final Phone phone = getPhone(subId); |
| 4111 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4112 | return phone.getCdmaMin(); |
| 4113 | } else { |
| 4114 | return null; |
| 4115 | } |
| 4116 | } finally { |
| 4117 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4118 | } |
| 4119 | } |
| 4120 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4121 | @Override |
| 4122 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4123 | INumberVerificationCallback callback, String callingPackage) { |
| 4124 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4125 | != PERMISSION_GRANTED) { |
| 4126 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4127 | } |
| 4128 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4129 | |
| 4130 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4131 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4132 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4133 | + "calling package: " + callingPackage |
| 4134 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4135 | } |
| 4136 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4137 | enforceTelephonyFeatureWithException(callingPackage, |
| 4138 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4139 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4140 | if (range == null) { |
| 4141 | throw new NullPointerException("Range must be non-null"); |
| 4142 | } |
| 4143 | |
| 4144 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4145 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4146 | |
| 4147 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4148 | } |
| 4149 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4150 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4151 | * Returns true if CDMA provisioning needs to run. |
| 4152 | */ |
| 4153 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4154 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4155 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4156 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4159 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(identity); |
| 4162 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4166 | * Sets the voice mail number of a given subId. |
| 4167 | */ |
| 4168 | @Override |
| 4169 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4170 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4171 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4173 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4174 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4175 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4176 | final long identity = Binder.clearCallingIdentity(); |
| 4177 | try { |
| 4178 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4179 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4180 | return success; |
| 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(identity); |
| 4183 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4184 | } |
| 4185 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4186 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4187 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4188 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4189 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4190 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4191 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4192 | throw new SecurityException("caller must be system dialer"); |
| 4193 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4194 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4195 | enforceTelephonyFeatureWithException(callingPackage, |
| 4196 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4197 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4198 | final long identity = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4201 | if (phoneAccountHandle == null) { |
| 4202 | return null; |
| 4203 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4204 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4207 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4211 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4212 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4213 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4215 | mApp, subId, callingPackage, callingFeatureId, |
| 4216 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4217 | return null; |
| 4218 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4220 | enforceTelephonyFeatureWithException(callingPackage, |
| 4221 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4222 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4223 | final long identity = Binder.clearCallingIdentity(); |
| 4224 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4225 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(identity); |
| 4228 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4232 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4233 | VisualVoicemailSmsFilterSettings settings) { |
| 4234 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4236 | enforceTelephonyFeatureWithException(callingPackage, |
| 4237 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
| 4238 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4239 | final long identity = Binder.clearCallingIdentity(); |
| 4240 | try { |
| 4241 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4242 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4243 | } finally { |
| 4244 | Binder.restoreCallingIdentity(identity); |
| 4245 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4249 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4250 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4252 | enforceTelephonyFeatureWithException(callingPackage, |
| 4253 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4255 | final long identity = Binder.clearCallingIdentity(); |
| 4256 | try { |
| 4257 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4258 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | } finally { |
| 4260 | Binder.restoreCallingIdentity(identity); |
| 4261 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4265 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4266 | String callingPackage, int subId) { |
| 4267 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4268 | |
| 4269 | final long identity = Binder.clearCallingIdentity(); |
| 4270 | try { |
| 4271 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4272 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4273 | } finally { |
| 4274 | Binder.restoreCallingIdentity(identity); |
| 4275 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4279 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4280 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4281 | |
| 4282 | final long identity = Binder.clearCallingIdentity(); |
| 4283 | try { |
| 4284 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4285 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4286 | } finally { |
| 4287 | Binder.restoreCallingIdentity(identity); |
| 4288 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4292 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4293 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4294 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4295 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4296 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4297 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4298 | |
| 4299 | enforceTelephonyFeatureWithException(callingPackage, |
| 4300 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4301 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4302 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4303 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4304 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4305 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4306 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4307 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4308 | * Sets the voice activation state of a given subId. |
| 4309 | */ |
| 4310 | @Override |
| 4311 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4312 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4313 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4315 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4316 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4317 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4318 | final long identity = Binder.clearCallingIdentity(); |
| 4319 | try { |
| 4320 | final Phone phone = getPhone(subId); |
| 4321 | if (phone != null) { |
| 4322 | phone.setVoiceActivationState(activationState); |
| 4323 | } else { |
| 4324 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4325 | } |
| 4326 | } finally { |
| 4327 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4328 | } |
| 4329 | } |
| 4330 | |
| 4331 | /** |
| 4332 | * Sets the data activation state of a given subId. |
| 4333 | */ |
| 4334 | @Override |
| 4335 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4336 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4337 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4338 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4339 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4340 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4341 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4342 | final long identity = Binder.clearCallingIdentity(); |
| 4343 | try { |
| 4344 | final Phone phone = getPhone(subId); |
| 4345 | if (phone != null) { |
| 4346 | phone.setDataActivationState(activationState); |
| 4347 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4348 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4349 | } |
| 4350 | } finally { |
| 4351 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4352 | } |
| 4353 | } |
| 4354 | |
| 4355 | /** |
| 4356 | * Returns the voice activation state of a given subId. |
| 4357 | */ |
| 4358 | @Override |
| 4359 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4360 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4361 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4362 | enforceTelephonyFeatureWithException(callingPackage, |
| 4363 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4364 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4365 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | final long identity = Binder.clearCallingIdentity(); |
| 4367 | try { |
| 4368 | if (phone != null) { |
| 4369 | return phone.getVoiceActivationState(); |
| 4370 | } else { |
| 4371 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4372 | } |
| 4373 | } finally { |
| 4374 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4375 | } |
| 4376 | } |
| 4377 | |
| 4378 | /** |
| 4379 | * Returns the data activation state of a given subId. |
| 4380 | */ |
| 4381 | @Override |
| 4382 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4383 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4384 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4385 | enforceTelephonyFeatureWithException(callingPackage, |
| 4386 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4387 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4388 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4389 | final long identity = Binder.clearCallingIdentity(); |
| 4390 | try { |
| 4391 | if (phone != null) { |
| 4392 | return phone.getDataActivationState(); |
| 4393 | } else { |
| 4394 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4395 | } |
| 4396 | } finally { |
| 4397 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4402 | * Returns the unread count of voicemails for a subId |
| 4403 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4404 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4405 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4406 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4407 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4408 | mApp, subId, callingPackage, callingFeatureId, |
| 4409 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4410 | return 0; |
| 4411 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
| 4414 | final Phone phone = getPhone(subId); |
| 4415 | if (phone != null) { |
| 4416 | return phone.getVoiceMessageCount(); |
| 4417 | } else { |
| 4418 | return 0; |
| 4419 | } |
| 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4422 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4426 | * returns true, if the device is in a state where both voice and data |
| 4427 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4428 | */ |
| 4429 | @Override |
| 4430 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4431 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4432 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4433 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4434 | final long identity = Binder.clearCallingIdentity(); |
| 4435 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4436 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4437 | } finally { |
| 4438 | Binder.restoreCallingIdentity(identity); |
| 4439 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4443 | * Send the dialer code if called from the current default dialer or the caller has |
| 4444 | * carrier privilege. |
| 4445 | * @param inputCode The dialer code to send |
| 4446 | */ |
| 4447 | @Override |
| 4448 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4449 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4450 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4451 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4452 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4453 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4454 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4455 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4457 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4458 | enforceTelephonyFeatureWithException(callingPackage, |
| 4459 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4460 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | final long identity = Binder.clearCallingIdentity(); |
| 4462 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4463 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4464 | } finally { |
| 4465 | Binder.restoreCallingIdentity(identity); |
| 4466 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4467 | } |
| 4468 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4469 | @Override |
| 4470 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4471 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4472 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4473 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4474 | |
| 4475 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4476 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4477 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
| 4480 | if (!isActiveSubscription(subId)) { |
| 4481 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4482 | } |
| 4483 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4486 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4487 | } |
| 4488 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4489 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4490 | public boolean isInEmergencySmsMode() { |
| 4491 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4492 | |
| 4493 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4494 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4495 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4496 | final long identity = Binder.clearCallingIdentity(); |
| 4497 | try { |
| 4498 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4499 | if (phone.isInEmergencySmsMode()) { |
| 4500 | return true; |
| 4501 | } |
| 4502 | } |
| 4503 | } finally { |
| 4504 | Binder.restoreCallingIdentity(identity); |
| 4505 | } |
| 4506 | return false; |
| 4507 | } |
| 4508 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4509 | /** |
| 4510 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4511 | * @param subId The subscription to use to check the configuration. |
| 4512 | * @param c The callback that will be used to send the result. |
| 4513 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4514 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4515 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4516 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4517 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4518 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4519 | |
| 4520 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4521 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4522 | "IMS not available on device."); |
| 4523 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4524 | final long token = Binder.clearCallingIdentity(); |
| 4525 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4526 | int slotId = getSlotIndexOrException(subId); |
| 4527 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4528 | |
| 4529 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4530 | if (controller != null) { |
| 4531 | ImsManager imsManager = controller.getImsManager(subId); |
| 4532 | if (imsManager != null) { |
| 4533 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4534 | } else { |
| 4535 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4536 | } |
| 4537 | } else { |
| 4538 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4539 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4540 | } catch (ImsException e) { |
| 4541 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4542 | } finally { |
| 4543 | Binder.restoreCallingIdentity(token); |
| 4544 | } |
| 4545 | } |
| 4546 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4547 | /** |
| 4548 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4549 | * @param subId The subscription to use to check the configuration. |
| 4550 | * @param c The callback that will be used to send the result. |
| 4551 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4552 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4553 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4554 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4555 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4556 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4557 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4558 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4559 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4560 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4561 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4562 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4563 | if (controller != null) { |
| 4564 | ImsManager imsManager = controller.getImsManager(subId); |
| 4565 | if (imsManager != null) { |
| 4566 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4567 | } else { |
| 4568 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4569 | + "is inactive, ignoring unregister."); |
| 4570 | // If the ImsManager is not valid, just return, since the callback |
| 4571 | // will already have been removed internally. |
| 4572 | } |
| 4573 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4574 | } finally { |
| 4575 | Binder.restoreCallingIdentity(token); |
| 4576 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4579 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4580 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4581 | * @param subId The subscription to use to check the configuration. |
| 4582 | * @param c The callback that will be used to send the result. |
| 4583 | */ |
| 4584 | @Override |
| 4585 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4586 | throws RemoteException { |
| 4587 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4588 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4589 | |
| 4590 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4591 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4592 | "IMS not available on device."); |
| 4593 | } |
| 4594 | final long token = Binder.clearCallingIdentity(); |
| 4595 | try { |
| 4596 | int slotId = getSlotIndexOrException(subId); |
| 4597 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4598 | |
| 4599 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4600 | if (controller != null) { |
| 4601 | ImsManager imsManager = controller.getImsManager(subId); |
| 4602 | if (imsManager != null) { |
| 4603 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4604 | } else { |
| 4605 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4606 | } |
| 4607 | } else { |
| 4608 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4609 | } |
| 4610 | } catch (ImsException e) { |
| 4611 | throw new ServiceSpecificException(e.getCode()); |
| 4612 | } finally { |
| 4613 | Binder.restoreCallingIdentity(token); |
| 4614 | } |
| 4615 | } |
| 4616 | |
| 4617 | /** |
| 4618 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4619 | * @param subId The subscription to use to check the configuration. |
| 4620 | * @param c The callback that will be used to send the result. |
| 4621 | */ |
| 4622 | @Override |
| 4623 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4624 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4625 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4626 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4627 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4628 | } |
| 4629 | final long token = Binder.clearCallingIdentity(); |
| 4630 | |
| 4631 | try { |
| 4632 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4633 | if (controller != null) { |
| 4634 | ImsManager imsManager = controller.getImsManager(subId); |
| 4635 | if (imsManager != null) { |
| 4636 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4637 | } else { |
| 4638 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4639 | + "is inactive, ignoring unregister."); |
| 4640 | // If the ImsManager is not valid, just return, since the callback |
| 4641 | // will already have been removed internally. |
| 4642 | } |
| 4643 | } |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(token); |
| 4646 | } |
| 4647 | } |
| 4648 | |
| 4649 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4650 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4651 | */ |
| 4652 | @Override |
| 4653 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4654 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4655 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4656 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4657 | "IMS not available on device."); |
| 4658 | } |
| 4659 | final long token = Binder.clearCallingIdentity(); |
| 4660 | try { |
| 4661 | Phone phone = getPhone(subId); |
| 4662 | if (phone == null) { |
| 4663 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4664 | + subId + "'"); |
| 4665 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4666 | } |
| 4667 | phone.getImsRegistrationState(regState -> { |
| 4668 | try { |
| 4669 | consumer.accept((regState == null) |
| 4670 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4671 | } catch (RemoteException e) { |
| 4672 | // Ignore if the remote process is no longer available to call back. |
| 4673 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4674 | } |
| 4675 | }); |
| 4676 | } finally { |
| 4677 | Binder.restoreCallingIdentity(token); |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | /** |
| 4682 | * Get the transport type for the IMS service registration state. |
| 4683 | */ |
| 4684 | @Override |
| 4685 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4686 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4687 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4688 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4689 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4690 | "IMS not available on device."); |
| 4691 | } |
| 4692 | final long token = Binder.clearCallingIdentity(); |
| 4693 | try { |
| 4694 | Phone phone = getPhone(subId); |
| 4695 | if (phone == null) { |
| 4696 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4697 | + subId + "'"); |
| 4698 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4699 | } |
| 4700 | phone.getImsRegistrationTech(regTech -> { |
| 4701 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4702 | int regTechConverted = (regTech == null) |
| 4703 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4704 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4705 | regTechConverted); |
| 4706 | try { |
| 4707 | consumer.accept(regTechConverted); |
| 4708 | } catch (RemoteException e) { |
| 4709 | // Ignore if the remote process is no longer available to call back. |
| 4710 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4711 | } |
| 4712 | }); |
| 4713 | } finally { |
| 4714 | Binder.restoreCallingIdentity(token); |
| 4715 | } |
| 4716 | } |
| 4717 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4718 | /** |
| 4719 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4720 | * @param subId The subscription to use to check the configuration. |
| 4721 | * @param c The callback that will be used to send the result. |
| 4722 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4723 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4724 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4725 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4726 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4727 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4728 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4729 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4730 | "IMS not available on device."); |
| 4731 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4732 | final long token = Binder.clearCallingIdentity(); |
| 4733 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4734 | int slotId = getSlotIndexOrException(subId); |
| 4735 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4736 | |
| 4737 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4738 | if (controller != null) { |
| 4739 | ImsManager imsManager = controller.getImsManager(subId); |
| 4740 | if (imsManager != null) { |
| 4741 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4742 | } else { |
| 4743 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4744 | } |
| 4745 | } else { |
| 4746 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4747 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4748 | } catch (ImsException e) { |
| 4749 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4750 | } finally { |
| 4751 | Binder.restoreCallingIdentity(token); |
| 4752 | } |
| 4753 | } |
| 4754 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4755 | /** |
| 4756 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4757 | * @param subId The subscription to use to check the configuration. |
| 4758 | * @param c The callback that will be used to send the result. |
| 4759 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4760 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4761 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4762 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4763 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4764 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4765 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4766 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4767 | |
| 4768 | final long token = Binder.clearCallingIdentity(); |
| 4769 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4770 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4771 | if (controller != null) { |
| 4772 | ImsManager imsManager = controller.getImsManager(subId); |
| 4773 | if (imsManager != null) { |
| 4774 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4775 | } else { |
| 4776 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4777 | + " is inactive, ignoring unregister."); |
| 4778 | // If the ImsManager is not valid, just return, since the callback |
| 4779 | // will already have been removed internally. |
| 4780 | } |
| 4781 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4782 | } finally { |
| 4783 | Binder.restoreCallingIdentity(token); |
| 4784 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4788 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4789 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4790 | |
| 4791 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4792 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4793 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4794 | final long token = Binder.clearCallingIdentity(); |
| 4795 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4796 | int slotId = getSlotIndexOrException(subId); |
| 4797 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4798 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4799 | } catch (com.android.ims.ImsException e) { |
| 4800 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4801 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4802 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4803 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4804 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4805 | } finally { |
| 4806 | Binder.restoreCallingIdentity(token); |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4811 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4812 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4813 | |
| 4814 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4815 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4816 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4817 | final long token = Binder.clearCallingIdentity(); |
| 4818 | try { |
| 4819 | Phone phone = getPhone(subId); |
| 4820 | if (phone == null) return false; |
| 4821 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4822 | } catch (com.android.ims.ImsException e) { |
| 4823 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4824 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4825 | } finally { |
| 4826 | Binder.restoreCallingIdentity(token); |
| 4827 | } |
| 4828 | } |
| 4829 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4830 | /** |
| 4831 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4832 | * subscription. |
| 4833 | * @param subId The subscription to use to check the configuration. |
| 4834 | * @param callback The callback that will be used to send the result. |
| 4835 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4836 | * @param transportType The transport type of the MmTelFeature capability. |
| 4837 | */ |
| 4838 | @Override |
| 4839 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4840 | int transportType) { |
| 4841 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4842 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4843 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4844 | "IMS not available on device."); |
| 4845 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4846 | final long token = Binder.clearCallingIdentity(); |
| 4847 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4848 | int slotId = getSlotIndex(subId); |
| 4849 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4850 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4851 | + subId + "'"); |
| 4852 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4853 | } |
| 4854 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4855 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4856 | transportType, aBoolean -> { |
| 4857 | try { |
| 4858 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4859 | } catch (RemoteException e) { |
| 4860 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4861 | + "running. Ignore"); |
| 4862 | } |
| 4863 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4864 | } catch (ImsException e) { |
| 4865 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(token); |
| 4868 | } |
| 4869 | } |
| 4870 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4871 | /** |
| 4872 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4873 | * @param subId The subscription to use to check the configuration. |
| 4874 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4875 | @Override |
| 4876 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4877 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4878 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4879 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4880 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4881 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4882 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | final long token = Binder.clearCallingIdentity(); |
| 4884 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4885 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4886 | // 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] | 4887 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4888 | } catch (ImsException e) { |
| 4889 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4890 | } finally { |
| 4891 | Binder.restoreCallingIdentity(token); |
| 4892 | } |
| 4893 | } |
| 4894 | |
| 4895 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4896 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4897 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4898 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4899 | |
| 4900 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4901 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4902 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4903 | final long identity = Binder.clearCallingIdentity(); |
| 4904 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4905 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4906 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4907 | // 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] | 4908 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4909 | } catch (ImsException e) { |
| 4910 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4911 | } finally { |
| 4912 | Binder.restoreCallingIdentity(identity); |
| 4913 | } |
| 4914 | } |
| 4915 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4916 | /** |
| 4917 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4918 | * @param subId The subscription to use to check the configuration. |
| 4919 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4920 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4921 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4922 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4923 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4924 | |
| 4925 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4926 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4927 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4928 | final long identity = Binder.clearCallingIdentity(); |
| 4929 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4930 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4931 | // 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] | 4932 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4933 | } catch (ImsException e) { |
| 4934 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4935 | } finally { |
| 4936 | Binder.restoreCallingIdentity(identity); |
| 4937 | } |
| 4938 | } |
| 4939 | |
| 4940 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4941 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4943 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4944 | |
| 4945 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4946 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 4947 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4948 | final long identity = Binder.clearCallingIdentity(); |
| 4949 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4950 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4951 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4952 | // 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] | 4953 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4954 | } catch (ImsException e) { |
| 4955 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4956 | } finally { |
| 4957 | Binder.restoreCallingIdentity(identity); |
| 4958 | } |
| 4959 | } |
| 4960 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4961 | /** |
| 4962 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4963 | * @param subId The subscription to use to check the configuration. |
| 4964 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4965 | @Override |
| 4966 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4967 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4968 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4969 | |
| 4970 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4971 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 4972 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4973 | final long identity = Binder.clearCallingIdentity(); |
| 4974 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4975 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4976 | // 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] | 4977 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4978 | } catch (ImsException e) { |
| 4979 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4980 | } finally { |
| 4981 | Binder.restoreCallingIdentity(identity); |
| 4982 | } |
| 4983 | } |
| 4984 | |
| 4985 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4986 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4987 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4988 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4989 | |
| 4990 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4991 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 4992 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4993 | final long identity = Binder.clearCallingIdentity(); |
| 4994 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4995 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4996 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4997 | // 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] | 4998 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4999 | } catch (ImsException e) { |
| 5000 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5001 | } finally { |
| 5002 | Binder.restoreCallingIdentity(identity); |
| 5003 | } |
| 5004 | } |
| 5005 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5006 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5007 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5008 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5009 | * @param subId The subscription to use to check the configuration. |
| 5010 | */ |
| 5011 | @Override |
| 5012 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5013 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5014 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5015 | |
| 5016 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5017 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5018 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5019 | final long identity = Binder.clearCallingIdentity(); |
| 5020 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5021 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5022 | // 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] | 5023 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5024 | } catch (ImsException e) { |
| 5025 | throw new ServiceSpecificException(e.getCode()); |
| 5026 | } finally { |
| 5027 | Binder.restoreCallingIdentity(identity); |
| 5028 | } |
| 5029 | } |
| 5030 | |
| 5031 | /** |
| 5032 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5033 | * Requires MODIFY_PHONE_STATE permission. |
| 5034 | * @param subId The subscription to use to check the configuration. |
| 5035 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5036 | * false otherwise |
| 5037 | */ |
| 5038 | @Override |
| 5039 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5040 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5041 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5042 | |
| 5043 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5044 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5045 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5046 | final long identity = Binder.clearCallingIdentity(); |
| 5047 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5048 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5049 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5050 | // 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] | 5051 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5052 | } catch (ImsException e) { |
| 5053 | throw new ServiceSpecificException(e.getCode()); |
| 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
| 5056 | } |
| 5057 | } |
| 5058 | |
| 5059 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5060 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5061 | * @param subId The subscription to use to check the configuration. |
| 5062 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5063 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5064 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5065 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5066 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5067 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5068 | |
| 5069 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5070 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5071 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5072 | final long identity = Binder.clearCallingIdentity(); |
| 5073 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5074 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5075 | // 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] | 5076 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5077 | } catch (ImsException e) { |
| 5078 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5079 | } finally { |
| 5080 | Binder.restoreCallingIdentity(identity); |
| 5081 | } |
| 5082 | } |
| 5083 | |
| 5084 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5085 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5087 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5088 | |
| 5089 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5090 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5091 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5094 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5095 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5096 | // 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] | 5097 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5098 | } catch (ImsException e) { |
| 5099 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5100 | } finally { |
| 5101 | Binder.restoreCallingIdentity(identity); |
| 5102 | } |
| 5103 | } |
| 5104 | |
| 5105 | @Override |
| 5106 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5108 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5109 | |
| 5110 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5111 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5112 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5113 | final long identity = Binder.clearCallingIdentity(); |
| 5114 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5115 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5116 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5117 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5118 | } catch (ImsException e) { |
| 5119 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5120 | } finally { |
| 5121 | Binder.restoreCallingIdentity(identity); |
| 5122 | } |
| 5123 | } |
| 5124 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5125 | /** |
| 5126 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5127 | * @param subId The subscription to use to check the configuration. |
| 5128 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5129 | @Override |
| 5130 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5131 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5132 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5133 | |
| 5134 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5135 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5136 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5139 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5140 | // 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] | 5141 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5142 | } catch (ImsException e) { |
| 5143 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
| 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | @Override |
| 5150 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5152 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5153 | |
| 5154 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5155 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5156 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5157 | final long identity = Binder.clearCallingIdentity(); |
| 5158 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5159 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5160 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5161 | // 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] | 5162 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5163 | } catch (ImsException e) { |
| 5164 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5165 | } finally { |
| 5166 | Binder.restoreCallingIdentity(identity); |
| 5167 | } |
| 5168 | } |
| 5169 | |
| 5170 | @Override |
| 5171 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5172 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5173 | |
| 5174 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5175 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5176 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5177 | final long identity = Binder.clearCallingIdentity(); |
| 5178 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5179 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5180 | // 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] | 5181 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5182 | } catch (ImsException e) { |
| 5183 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5184 | } finally { |
| 5185 | Binder.restoreCallingIdentity(identity); |
| 5186 | } |
| 5187 | } |
| 5188 | |
| 5189 | @Override |
| 5190 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5192 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5193 | |
| 5194 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5195 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5196 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5197 | final long identity = Binder.clearCallingIdentity(); |
| 5198 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5199 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5200 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5201 | // 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] | 5202 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5203 | } catch (ImsException e) { |
| 5204 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
| 5207 | } |
| 5208 | } |
| 5209 | |
| 5210 | @Override |
| 5211 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5213 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5214 | |
| 5215 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5216 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5217 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5218 | final long identity = Binder.clearCallingIdentity(); |
| 5219 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5220 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5221 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5222 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5223 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5224 | } catch (ImsException e) { |
| 5225 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5226 | } finally { |
| 5227 | Binder.restoreCallingIdentity(identity); |
| 5228 | } |
| 5229 | } |
| 5230 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5231 | /** |
| 5232 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5233 | * @param subId The subscription to use to check the configuration. |
| 5234 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5235 | @Override |
| 5236 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5237 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5238 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5239 | |
| 5240 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5241 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5242 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5243 | final long identity = Binder.clearCallingIdentity(); |
| 5244 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5245 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5246 | // 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] | 5247 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5248 | } catch (ImsException e) { |
| 5249 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5250 | } finally { |
| 5251 | Binder.restoreCallingIdentity(identity); |
| 5252 | } |
| 5253 | } |
| 5254 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5255 | @Override |
| 5256 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5257 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5258 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5259 | final long identity = Binder.clearCallingIdentity(); |
| 5260 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5261 | if (!isImsAvailableOnDevice()) { |
| 5262 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5263 | "IMS not available on device."); |
| 5264 | } |
| 5265 | int slotId = getSlotIndexOrException(subId); |
| 5266 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5267 | |
| 5268 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5269 | if (controller != null) { |
| 5270 | ImsManager imsManager = controller.getImsManager(subId); |
| 5271 | if (imsManager != null) { |
| 5272 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5273 | } else { |
| 5274 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5275 | } |
| 5276 | } else { |
| 5277 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5278 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5279 | } catch (ImsException e) { |
| 5280 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5281 | } finally { |
| 5282 | Binder.restoreCallingIdentity(identity); |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | @Override |
| 5287 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5288 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5289 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5290 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5291 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5292 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5293 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5294 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5295 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5296 | if (controller != null) { |
| 5297 | ImsManager imsManager = controller.getImsManager(subId); |
| 5298 | if (imsManager != null) { |
| 5299 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5300 | } else { |
| 5301 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5302 | + " is inactive, ignoring unregister."); |
| 5303 | // If the ImsManager is not valid, just return, since the callback will already |
| 5304 | // have been removed internally. |
| 5305 | } |
| 5306 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5307 | } finally { |
| 5308 | Binder.restoreCallingIdentity(identity); |
| 5309 | } |
| 5310 | } |
| 5311 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5312 | @Override |
| 5313 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5314 | IFeatureProvisioningCallback callback) { |
| 5315 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5316 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5317 | |
| 5318 | final long identity = Binder.clearCallingIdentity(); |
| 5319 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5320 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5321 | } |
| 5322 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5323 | try { |
| 5324 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5325 | if (controller == null) { |
| 5326 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5327 | "Device does not support IMS"); |
| 5328 | } |
| 5329 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
| 5332 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | @Override |
| 5336 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5337 | IFeatureProvisioningCallback callback) { |
| 5338 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5339 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5340 | |
| 5341 | final long identity = Binder.clearCallingIdentity(); |
| 5342 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5343 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5344 | } |
| 5345 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5346 | try { |
| 5347 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5348 | if (controller == null) { |
| 5349 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5350 | return; |
| 5351 | } |
| 5352 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5353 | } finally { |
| 5354 | Binder.restoreCallingIdentity(identity); |
| 5355 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5356 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5357 | |
| 5358 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5360 | message); |
| 5361 | } |
| 5362 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5363 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5364 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5365 | boolean isProvisioned) { |
| 5366 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5367 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5368 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5369 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5370 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5371 | final long identity = Binder.clearCallingIdentity(); |
| 5372 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5373 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5374 | if (controller == null) { |
| 5375 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5376 | return; |
| 5377 | } |
| 5378 | controller.setRcsProvisioningStatusForCapability( |
| 5379 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5380 | } finally { |
| 5381 | Binder.restoreCallingIdentity(identity); |
| 5382 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | |
| 5386 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5387 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5388 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5389 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5390 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5391 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5392 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5393 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5394 | final long identity = Binder.clearCallingIdentity(); |
| 5395 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5396 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5397 | if (controller == null) { |
| 5398 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5399 | |
| 5400 | // device does not support IMS, this method will return true always. |
| 5401 | return true; |
| 5402 | } |
| 5403 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5404 | } finally { |
| 5405 | Binder.restoreCallingIdentity(identity); |
| 5406 | } |
| 5407 | } |
| 5408 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5409 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5410 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5411 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5412 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5413 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5414 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5415 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5416 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5417 | final long identity = Binder.clearCallingIdentity(); |
| 5418 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5419 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5420 | if (controller == null) { |
| 5421 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5422 | return; |
| 5423 | } |
| 5424 | controller.setImsProvisioningStatusForCapability( |
| 5425 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
| 5428 | } |
| 5429 | } |
| 5430 | |
| 5431 | @Override |
| 5432 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5433 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5434 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5435 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5436 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5437 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5438 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5439 | final long identity = Binder.clearCallingIdentity(); |
| 5440 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5441 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5442 | if (controller == null) { |
| 5443 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5444 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5445 | // device does not support IMS, this method will return true always. |
| 5446 | return true; |
| 5447 | } |
| 5448 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5449 | } finally { |
| 5450 | Binder.restoreCallingIdentity(identity); |
| 5451 | } |
| 5452 | } |
| 5453 | |
| 5454 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5455 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5456 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5457 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5458 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5459 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5460 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5461 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5462 | final long identity = Binder.clearCallingIdentity(); |
| 5463 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5464 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5465 | if (controller == null) { |
| 5466 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5467 | |
| 5468 | // device does not support IMS, this method will return false |
| 5469 | return false; |
| 5470 | } |
| 5471 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5472 | } finally { |
| 5473 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5474 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5478 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5479 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5480 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5481 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5482 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5483 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5484 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5485 | final long identity = Binder.clearCallingIdentity(); |
| 5486 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5487 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5488 | if (controller == null) { |
| 5489 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5490 | |
| 5491 | // device does not support IMS, this method will return false |
| 5492 | return false; |
| 5493 | } |
| 5494 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
| 5497 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5498 | } |
| 5499 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5500 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5501 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5502 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5503 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5504 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5505 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5506 | mApp, subId, "getImsProvisioningInt"); |
| 5507 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5508 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5509 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5510 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5511 | final long identity = Binder.clearCallingIdentity(); |
| 5512 | try { |
| 5513 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5514 | int slotId = getSlotIndex(subId); |
| 5515 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5516 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5517 | + subId + "' for key:" + key); |
| 5518 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5519 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5520 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5521 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5522 | if (controller == null) { |
| 5523 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5524 | |
| 5525 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5526 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5527 | } |
| 5528 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5529 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5530 | return retVal; |
| 5531 | } |
| 5532 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5533 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5534 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5535 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5536 | + subId + "' for key:" + key); |
| 5537 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5538 | } finally { |
| 5539 | Binder.restoreCallingIdentity(identity); |
| 5540 | } |
| 5541 | } |
| 5542 | |
| 5543 | @Override |
| 5544 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5545 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5546 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5547 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5548 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5549 | mApp, subId, "getImsProvisioningString"); |
| 5550 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5551 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5552 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5553 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5554 | final long identity = Binder.clearCallingIdentity(); |
| 5555 | try { |
| 5556 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5557 | int slotId = getSlotIndex(subId); |
| 5558 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5559 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5560 | + subId + "' for key:" + key); |
| 5561 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5562 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5563 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5564 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5565 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5566 | + subId + "' for key:" + key); |
| 5567 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5568 | } finally { |
| 5569 | Binder.restoreCallingIdentity(identity); |
| 5570 | } |
| 5571 | } |
| 5572 | |
| 5573 | @Override |
| 5574 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5575 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5576 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5577 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5579 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5580 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5581 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5582 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5583 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5584 | final long identity = Binder.clearCallingIdentity(); |
| 5585 | try { |
| 5586 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5587 | int slotId = getSlotIndex(subId); |
| 5588 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5589 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5590 | + subId + "' for key:" + key); |
| 5591 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5592 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5593 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5594 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5595 | if (controller == null) { |
| 5596 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5597 | |
| 5598 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5599 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5600 | } |
| 5601 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5602 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5603 | return retVal; |
| 5604 | } |
| 5605 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5606 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5607 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5608 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5609 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5610 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5611 | } finally { |
| 5612 | Binder.restoreCallingIdentity(identity); |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | @Override |
| 5617 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5618 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5619 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5620 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5621 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5622 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5623 | |
| 5624 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5625 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5626 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5627 | final long identity = Binder.clearCallingIdentity(); |
| 5628 | try { |
| 5629 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5630 | int slotId = getSlotIndex(subId); |
| 5631 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5632 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5633 | + subId + "' for key:" + key); |
| 5634 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5635 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5636 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5637 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5638 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5639 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5640 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
| 5643 | } |
| 5644 | } |
| 5645 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5646 | /** |
| 5647 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5648 | * for the given slot ID or no ImsResolver instance has been created. |
| 5649 | * @param slotId The slot ID that the IMS service is created for. |
| 5650 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5651 | */ |
| 5652 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5653 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5654 | ImsFeature.FEATURE_MMTEL)) { |
| 5655 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5656 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5657 | } |
| 5658 | } |
| 5659 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5660 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5661 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5662 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5663 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5664 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5665 | } |
| 5666 | return slotId; |
| 5667 | } |
| 5668 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5669 | private int getSlotIndex(int subId) { |
| 5670 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5671 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5672 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5673 | } |
| 5674 | return slotId; |
| 5675 | } |
| 5676 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5677 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5678 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5679 | */ |
| 5680 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5681 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5682 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5683 | try { |
| 5684 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5685 | } catch (SecurityException se) { |
| 5686 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5687 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5688 | + Binder.getCallingUid()); |
| 5689 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5690 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5691 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5692 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5693 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5694 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5695 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5696 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5697 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5698 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5699 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5700 | enforceTelephonyFeatureWithException(callingPackage, |
| 5701 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5702 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5703 | final long identity = Binder.clearCallingIdentity(); |
| 5704 | try { |
| 5705 | final Phone phone = getPhone(subId); |
| 5706 | if (phone != null) { |
| 5707 | return phone.getServiceState().getDataNetworkType(); |
| 5708 | } else { |
| 5709 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5710 | } |
| 5711 | } finally { |
| 5712 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5714 | } |
| 5715 | |
| 5716 | /** |
| 5717 | * Returns the data network type |
| 5718 | */ |
| 5719 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5720 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5721 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5722 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | /** |
| 5726 | * Returns the data network type for a subId |
| 5727 | */ |
| 5728 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5729 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5730 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5731 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5732 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5733 | mApp, functionName)) { |
| 5734 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5735 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5736 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5737 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5738 | } |
| 5739 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5740 | enforceTelephonyFeatureWithException(callingPackage, |
| 5741 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5742 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5743 | final long identity = Binder.clearCallingIdentity(); |
| 5744 | try { |
| 5745 | final Phone phone = getPhone(subId); |
| 5746 | if (phone != null) { |
| 5747 | return phone.getServiceState().getDataNetworkType(); |
| 5748 | } else { |
| 5749 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5750 | } |
| 5751 | } finally { |
| 5752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5753 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5757 | * Returns the Voice network type for a subId |
| 5758 | */ |
| 5759 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5760 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5761 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5762 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5763 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5764 | mApp, functionName)) { |
| 5765 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5766 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5767 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5768 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5771 | enforceTelephonyFeatureWithException(callingPackage, |
| 5772 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5773 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | final long identity = Binder.clearCallingIdentity(); |
| 5775 | try { |
| 5776 | final Phone phone = getPhone(subId); |
| 5777 | if (phone != null) { |
| 5778 | return phone.getServiceState().getVoiceNetworkType(); |
| 5779 | } else { |
| 5780 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5781 | } |
| 5782 | } finally { |
| 5783 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5785 | } |
| 5786 | |
| 5787 | /** |
| 5788 | * @return true if a ICC card is present |
| 5789 | */ |
| 5790 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5791 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5792 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5793 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5794 | } |
| 5795 | |
| 5796 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5797 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5798 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5799 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5800 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5801 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5802 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5803 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5804 | final long identity = Binder.clearCallingIdentity(); |
| 5805 | try { |
| 5806 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5807 | if (phone != null) { |
| 5808 | return phone.getIccCard().hasIccCard(); |
| 5809 | } else { |
| 5810 | return false; |
| 5811 | } |
| 5812 | } finally { |
| 5813 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5814 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | /** |
| 5818 | * Return if the current radio is LTE on CDMA. This |
| 5819 | * is a tri-state return value as for a period of time |
| 5820 | * the mode may be unknown. |
| 5821 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5822 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5823 | * @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] | 5824 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5825 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5826 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5827 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5828 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5829 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5830 | } |
| 5831 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5832 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5833 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5834 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5835 | try { |
| 5836 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5837 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5838 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5839 | } |
| 5840 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5841 | enforceTelephonyFeatureWithException(callingPackage, |
| 5842 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5843 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5844 | final long identity = Binder.clearCallingIdentity(); |
| 5845 | try { |
| 5846 | final Phone phone = getPhone(subId); |
| 5847 | if (phone == null) { |
| 5848 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5849 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5850 | return TelephonyProperties.lte_on_cdma_device() |
| 5851 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5852 | } |
| 5853 | } finally { |
| 5854 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5855 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5856 | } |
| 5857 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5858 | /** |
| 5859 | * {@hide} |
| 5860 | * Returns Default subId, 0 in the case of single standby. |
| 5861 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5862 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5863 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5866 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5867 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5870 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5871 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5872 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5873 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5874 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5875 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5876 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5877 | } |
| 5878 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5879 | /** |
| 5880 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5881 | */ |
| 5882 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | final long identity = Binder.clearCallingIdentity(); |
| 5884 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5885 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5887 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5888 | } finally { |
| 5889 | Binder.restoreCallingIdentity(identity); |
| 5890 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | /** |
| 5894 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5895 | */ |
| 5896 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | final long identity = Binder.clearCallingIdentity(); |
| 5898 | try { |
| 5899 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5900 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5901 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5902 | } finally { |
| 5903 | Binder.restoreCallingIdentity(identity); |
| 5904 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5905 | } |
| 5906 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5907 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5908 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5909 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5910 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5911 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5912 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5913 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5914 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5915 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5916 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5917 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5918 | } |
| 5919 | return PhoneFactory.getPhone(phoneId); |
| 5920 | } |
| 5921 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5922 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5923 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5924 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5925 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5926 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5927 | /*message=*/ "iccOpenLogicalChannel"); |
| 5928 | |
| 5929 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5930 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5931 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5932 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5933 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5934 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 5935 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5936 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5937 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5938 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5939 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5940 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5941 | Phone phone; |
| 5942 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5944 | mApp, request.subId, message); |
| 5945 | phone = getPhoneFromSubId(request.subId); |
| 5946 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5947 | enforceModifyPermission(); |
| 5948 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5949 | } else { |
| 5950 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5951 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5952 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5956 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5957 | final long identity = Binder.clearCallingIdentity(); |
| 5958 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5959 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5960 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5961 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5962 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5963 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5964 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5965 | loge("The calling package is not allowed to access ISD-R."); |
| 5966 | throw new SecurityException( |
| 5967 | "The calling package is not allowed to access ISD-R."); |
| 5968 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5969 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5970 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5972 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5973 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | return response; |
| 5975 | } finally { |
| 5976 | Binder.restoreCallingIdentity(identity); |
| 5977 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5981 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5982 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5983 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 5984 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5985 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5986 | /*message=*/"iccCloseLogicalChannel"); |
| 5987 | |
| 5988 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5989 | |
| 5990 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5991 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5992 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5993 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5994 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5995 | // before this feature is enabled, this API should only return false if |
| 5996 | // the operation fails instead of throwing runtime exception for |
| 5997 | // backward-compatibility. |
| 5998 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5999 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | final long identity = Binder.clearCallingIdentity(); |
| 6001 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6002 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6003 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6004 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6005 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6006 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6007 | Boolean success = false; |
| 6008 | if (result instanceof RuntimeException) { |
| 6009 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6010 | if (shouldThrowExceptionOnFailure) { |
| 6011 | throw (RuntimeException) result; |
| 6012 | } else { |
| 6013 | return false; |
| 6014 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6015 | } else if (result instanceof Boolean) { |
| 6016 | success = (Boolean) result; |
| 6017 | } else { |
| 6018 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6019 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6020 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | return success; |
| 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6024 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6028 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6029 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6031 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6032 | |
| 6033 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6034 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6035 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6036 | if (DBG) { |
| 6037 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6038 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6039 | + p3 + " data=" + data); |
| 6040 | } |
| 6041 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6042 | command, p1, p2, p3, data); |
| 6043 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6044 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6045 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6046 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6047 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6048 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6049 | |
| 6050 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6051 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6052 | "iccTransmitApduLogicalChannelBySlot"); |
| 6053 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6054 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6055 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6056 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6057 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6058 | } |
| 6059 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6060 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6061 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6065 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6066 | final long identity = Binder.clearCallingIdentity(); |
| 6067 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6068 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6069 | return ""; |
| 6070 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6072 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6073 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6074 | null /* workSource */); |
| 6075 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6076 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6077 | // Append the returned status code to the end of the response payload. |
| 6078 | String s = Integer.toHexString( |
| 6079 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6080 | if (response.payload != null) { |
| 6081 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6082 | } |
| 6083 | return s; |
| 6084 | } finally { |
| 6085 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6086 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6087 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6088 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6089 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6090 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6091 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6093 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6095 | |
| 6096 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6097 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6098 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6099 | if (DBG) { |
| 6100 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6101 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6102 | } |
| 6103 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6104 | cla, command, p1, p2, p3, data); |
| 6105 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6106 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6107 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6108 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6109 | 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] | 6110 | enforceModifyPermission(); |
| 6111 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6112 | |
| 6113 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6114 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6115 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6116 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6117 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6118 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6119 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6123 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6124 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6128 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6129 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6130 | final long identity = Binder.clearCallingIdentity(); |
| 6131 | try { |
| 6132 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6133 | && TextUtils.equals(ISDR_AID, data)) { |
| 6134 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6135 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6136 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | if (bestComponent == null |
| 6138 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6139 | loge("The calling package is not allowed to select ISD-R."); |
| 6140 | throw new SecurityException( |
| 6141 | "The calling package is not allowed to select ISD-R."); |
| 6142 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6143 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6144 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6145 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6146 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6147 | null /* workSource */); |
| 6148 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6149 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6150 | // Append the returned status code to the end of the response payload. |
| 6151 | String s = Integer.toHexString( |
| 6152 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6153 | if (response.payload != null) { |
| 6154 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6155 | } |
| 6156 | return s; |
| 6157 | } finally { |
| 6158 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6159 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6160 | } |
| 6161 | |
| 6162 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6163 | 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] | 6164 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6166 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6167 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6168 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6169 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | final long identity = Binder.clearCallingIdentity(); |
| 6172 | try { |
| 6173 | if (DBG) { |
| 6174 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6175 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6176 | } |
| 6177 | |
| 6178 | IccIoResult response = |
| 6179 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6180 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6181 | subId); |
| 6182 | |
| 6183 | if (DBG) { |
| 6184 | log("Exchange SIM_IO [R]" + response); |
| 6185 | } |
| 6186 | |
| 6187 | byte[] result = null; |
| 6188 | int length = 2; |
| 6189 | if (response.payload != null) { |
| 6190 | length = 2 + response.payload.length; |
| 6191 | result = new byte[length]; |
| 6192 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6193 | } else { |
| 6194 | result = new byte[length]; |
| 6195 | } |
| 6196 | |
| 6197 | result[length - 1] = (byte) response.sw2; |
| 6198 | result[length - 2] = (byte) response.sw1; |
| 6199 | return result; |
| 6200 | } finally { |
| 6201 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6202 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6203 | } |
| 6204 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6205 | /** |
| 6206 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6207 | * on a particular subscription |
| 6208 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6209 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6210 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6211 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6212 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6213 | return null; |
| 6214 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6215 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6216 | enforceTelephonyFeatureWithException(callingPackage, |
| 6217 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | final long identity = Binder.clearCallingIdentity(); |
| 6220 | try { |
| 6221 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6222 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6223 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6224 | return null; |
| 6225 | } |
| 6226 | Object response = sendRequest( |
| 6227 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6228 | if (response instanceof String[]) { |
| 6229 | return (String[]) response; |
| 6230 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6231 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6232 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6233 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6234 | } finally { |
| 6235 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6236 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6237 | } |
| 6238 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6239 | /** |
| 6240 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6241 | * subscription. |
| 6242 | * |
| 6243 | * @param subId the id of the subscription. |
| 6244 | * @param appType the uicc app type, must be USIM or SIM. |
| 6245 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6246 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6247 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6248 | * @return number of fplmns that is successfully written to the SIM. |
| 6249 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6250 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6251 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6252 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6253 | mApp, subId, "setForbiddenPlmns"); |
| 6254 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6255 | enforceTelephonyFeatureWithException(callingPackage, |
| 6256 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6257 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6258 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6259 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6260 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6261 | } |
| 6262 | if (fplmns == null) { |
| 6263 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6264 | } |
| 6265 | for (String fplmn : fplmns) { |
| 6266 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6267 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6268 | } |
| 6269 | } |
| 6270 | final long identity = Binder.clearCallingIdentity(); |
| 6271 | try { |
| 6272 | Object response = sendRequest( |
| 6273 | CMD_SET_FORBIDDEN_PLMNS, |
| 6274 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6275 | subId); |
| 6276 | return (int) response; |
| 6277 | } finally { |
| 6278 | Binder.restoreCallingIdentity(identity); |
| 6279 | } |
| 6280 | } |
| 6281 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6282 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6283 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6284 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6285 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6286 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6287 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6288 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6289 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | final long identity = Binder.clearCallingIdentity(); |
| 6291 | try { |
| 6292 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6293 | if (response.payload == null) { |
| 6294 | return ""; |
| 6295 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6296 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6297 | // Append the returned status code to the end of the response payload. |
| 6298 | String s = Integer.toHexString( |
| 6299 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6300 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6301 | return s; |
| 6302 | } finally { |
| 6303 | Binder.restoreCallingIdentity(identity); |
| 6304 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6305 | } |
| 6306 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6307 | /** |
| 6308 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6309 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6310 | * |
| 6311 | * @param itemID the ID of the item to read |
| 6312 | * @return the NV item as a String, or null on error. |
| 6313 | */ |
| 6314 | @Override |
| 6315 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6316 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6318 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6319 | |
| 6320 | final long identity = Binder.clearCallingIdentity(); |
| 6321 | try { |
| 6322 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6323 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6324 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6325 | return value; |
| 6326 | } finally { |
| 6327 | Binder.restoreCallingIdentity(identity); |
| 6328 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | /** |
| 6332 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6333 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6334 | * |
| 6335 | * @param itemID the ID of the item to read |
| 6336 | * @param itemValue the value to write, as a String |
| 6337 | * @return true on success; false on any failure |
| 6338 | */ |
| 6339 | @Override |
| 6340 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6341 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6342 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6343 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6344 | |
| 6345 | final long identity = Binder.clearCallingIdentity(); |
| 6346 | try { |
| 6347 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6348 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6349 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6350 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6351 | return success; |
| 6352 | } finally { |
| 6353 | Binder.restoreCallingIdentity(identity); |
| 6354 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | /** |
| 6358 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6359 | * Used for device configuration by some CDMA operators. |
| 6360 | * |
| 6361 | * @param preferredRoamingList byte array containing the new PRL |
| 6362 | * @return true on success; false on any failure |
| 6363 | */ |
| 6364 | @Override |
| 6365 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6367 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6368 | |
| 6369 | final long identity = Binder.clearCallingIdentity(); |
| 6370 | try { |
| 6371 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6372 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6373 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6374 | return success; |
| 6375 | } finally { |
| 6376 | Binder.restoreCallingIdentity(identity); |
| 6377 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6381 | * 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] | 6382 | * Used for device configuration by some CDMA operators. |
| 6383 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6384 | * @param slotIndex - device slot. |
| 6385 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6386 | * @return true on success; false on any failure |
| 6387 | */ |
| 6388 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6389 | public boolean resetModemConfig(int slotIndex) { |
| 6390 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6391 | if (phone != null) { |
| 6392 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6393 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6394 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6395 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6396 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6397 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6398 | final long identity = Binder.clearCallingIdentity(); |
| 6399 | try { |
| 6400 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6401 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6402 | return success; |
| 6403 | } finally { |
| 6404 | Binder.restoreCallingIdentity(identity); |
| 6405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6406 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6407 | return false; |
| 6408 | } |
| 6409 | |
| 6410 | /** |
| 6411 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6412 | * |
| 6413 | * @param slotIndex - device slot. |
| 6414 | * |
| 6415 | * @return true on success; false on any failure |
| 6416 | */ |
| 6417 | @Override |
| 6418 | public boolean rebootModem(int slotIndex) { |
| 6419 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6420 | if (phone != null) { |
| 6421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6422 | mApp, phone.getSubId(), "rebootModem"); |
| 6423 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6424 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6425 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6426 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6427 | final long identity = Binder.clearCallingIdentity(); |
| 6428 | try { |
| 6429 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6430 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6431 | return success; |
| 6432 | } finally { |
| 6433 | Binder.restoreCallingIdentity(identity); |
| 6434 | } |
| 6435 | } |
| 6436 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6437 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6438 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6439 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6440 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6441 | * {@link #disableIms(int)}. |
| 6442 | * @param slotIndex device slot. |
| 6443 | */ |
| 6444 | public void resetIms(int slotIndex) { |
| 6445 | enforceModifyPermission(); |
| 6446 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6447 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6448 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6449 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
| 6452 | if (mImsResolver == null) { |
| 6453 | // may happen if the does not support IMS. |
| 6454 | return; |
| 6455 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6456 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6457 | } finally { |
| 6458 | Binder.restoreCallingIdentity(identity); |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6463 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6464 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6465 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6466 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6467 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6468 | |
| 6469 | final long identity = Binder.clearCallingIdentity(); |
| 6470 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6471 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6472 | // may happen if the device does not support IMS. |
| 6473 | return; |
| 6474 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6475 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6476 | } finally { |
| 6477 | Binder.restoreCallingIdentity(identity); |
| 6478 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6482 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6483 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6484 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6485 | public void disableIms(int slotId) { |
| 6486 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6487 | |
| 6488 | final long identity = Binder.clearCallingIdentity(); |
| 6489 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6490 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6491 | // may happen if the device does not support IMS. |
| 6492 | return; |
| 6493 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6494 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6495 | } finally { |
| 6496 | Binder.restoreCallingIdentity(identity); |
| 6497 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6501 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6502 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6503 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6504 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6505 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6506 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6507 | |
| 6508 | final long identity = Binder.clearCallingIdentity(); |
| 6509 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6510 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6511 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6512 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6513 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6514 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6515 | } finally { |
| 6516 | Binder.restoreCallingIdentity(identity); |
| 6517 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6518 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6519 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6520 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6521 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6522 | @Override |
| 6523 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6524 | enforceModifyPermission(); |
| 6525 | |
| 6526 | final long identity = Binder.clearCallingIdentity(); |
| 6527 | try { |
| 6528 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6529 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(identity); |
| 6532 | } |
| 6533 | } |
| 6534 | |
| 6535 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6536 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6537 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6538 | */ |
| 6539 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6540 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6541 | |
| 6542 | final long identity = Binder.clearCallingIdentity(); |
| 6543 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6544 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6545 | // may happen if the device does not support IMS. |
| 6546 | return null; |
| 6547 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6548 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | } finally { |
| 6550 | Binder.restoreCallingIdentity(identity); |
| 6551 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6552 | } |
| 6553 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6554 | /** |
| 6555 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6556 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6557 | */ |
| 6558 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6559 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | |
| 6561 | final long identity = Binder.clearCallingIdentity(); |
| 6562 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6563 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6564 | // may happen if the device does not support IMS. |
| 6565 | return null; |
| 6566 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6567 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6568 | } finally { |
| 6569 | Binder.restoreCallingIdentity(identity); |
| 6570 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6571 | } |
| 6572 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6573 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6574 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6575 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6576 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6577 | * @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] | 6578 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6579 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6580 | * @param packageName The name of the package that the current configuration will be replaced |
| 6581 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6582 | * @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] | 6583 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6584 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6585 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6586 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6588 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6589 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6590 | final long identity = Binder.clearCallingIdentity(); |
| 6591 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6592 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6593 | // may happen if the device does not support IMS. |
| 6594 | return false; |
| 6595 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6596 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6597 | for (int featureType : featureTypes) { |
| 6598 | featureConfig.put(featureType, packageName); |
| 6599 | } |
| 6600 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6601 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 | } finally { |
| 6603 | Binder.restoreCallingIdentity(identity); |
| 6604 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6605 | } |
| 6606 | |
| 6607 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6608 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6609 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6610 | * |
| 6611 | * This should only be used for testing. |
| 6612 | * |
| 6613 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6614 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6615 | */ |
| 6616 | @Override |
| 6617 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6618 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6619 | "clearCarrierImsServiceOverride"); |
| 6620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6621 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6622 | |
| 6623 | final long identity = Binder.clearCallingIdentity(); |
| 6624 | try { |
| 6625 | if (mImsResolver == null) { |
| 6626 | // may happen if the device does not support IMS. |
| 6627 | return false; |
| 6628 | } |
| 6629 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6630 | } finally { |
| 6631 | Binder.restoreCallingIdentity(identity); |
| 6632 | } |
| 6633 | } |
| 6634 | |
| 6635 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6636 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6637 | * |
| 6638 | * @param slotId The slot that the ImsService is associated with. |
| 6639 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6640 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6641 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6642 | * @return the package name of the ImsService configuration. |
| 6643 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6644 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6645 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6646 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6647 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6648 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6650 | final long identity = Binder.clearCallingIdentity(); |
| 6651 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6652 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6653 | // may happen if the device does not support IMS. |
| 6654 | return ""; |
| 6655 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6656 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6657 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6658 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | } finally { |
| 6660 | Binder.restoreCallingIdentity(identity); |
| 6661 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6662 | } |
| 6663 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6664 | /** |
| 6665 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6666 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6667 | * @param callback A callback with an integer containing the |
| 6668 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6669 | */ |
| 6670 | @Override |
| 6671 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6672 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6673 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6674 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6675 | "IMS not available on device."); |
| 6676 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6677 | final long token = Binder.clearCallingIdentity(); |
| 6678 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6679 | int slotId = getSlotIndex(subId); |
| 6680 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6681 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6682 | + subId + "'"); |
| 6683 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6684 | } |
| 6685 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6686 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6687 | try { |
| 6688 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6689 | } catch (RemoteException e) { |
| 6690 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6691 | + "Ignore"); |
| 6692 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6693 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6694 | } catch (ImsException e) { |
| 6695 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6696 | } finally { |
| 6697 | Binder.restoreCallingIdentity(token); |
| 6698 | } |
| 6699 | } |
| 6700 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6701 | /** |
| 6702 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6703 | */ |
| 6704 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6705 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | |
| 6707 | final long identity = Binder.clearCallingIdentity(); |
| 6708 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6709 | // NOTE: Before S, this method only set the default phone. |
| 6710 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6711 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6712 | phone.setImsRegistrationState(registered); |
| 6713 | } |
| 6714 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | } finally { |
| 6716 | Binder.restoreCallingIdentity(identity); |
| 6717 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6721 | * Set the network selection mode to automatic. |
| 6722 | * |
| 6723 | */ |
| 6724 | @Override |
| 6725 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6727 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6729 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6730 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6731 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | final long identity = Binder.clearCallingIdentity(); |
| 6733 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6734 | if (!isActiveSubscription(subId)) { |
| 6735 | return; |
| 6736 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6737 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6738 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6739 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6740 | } finally { |
| 6741 | Binder.restoreCallingIdentity(identity); |
| 6742 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6743 | } |
| 6744 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6745 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6746 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6747 | * |
| 6748 | * @param subId the id of the subscription. |
| 6749 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6750 | * the operator to attach to. |
| 6751 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6752 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6753 | * normal network selection next time. |
| 6754 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6755 | */ |
| 6756 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6757 | public boolean setNetworkSelectionModeManual( |
| 6758 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6760 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6761 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6762 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6763 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6764 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6765 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6766 | if (!isActiveSubscription(subId)) { |
| 6767 | return false; |
| 6768 | } |
| 6769 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6771 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6773 | if (DBG) { |
| 6774 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6775 | + " operator: " + operatorInfo); |
| 6776 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6777 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6778 | } finally { |
| 6779 | Binder.restoreCallingIdentity(identity); |
| 6780 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6781 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6782 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6783 | * Get the manual network selection |
| 6784 | * |
| 6785 | * @param subId the id of the subscription. |
| 6786 | * |
| 6787 | * @return the previously saved user selected PLMN |
| 6788 | */ |
| 6789 | @Override |
| 6790 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6791 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6792 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6793 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6794 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6795 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6796 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6797 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6798 | final long identity = Binder.clearCallingIdentity(); |
| 6799 | try { |
| 6800 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6801 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6802 | } |
| 6803 | |
| 6804 | final Phone phone = getPhone(subId); |
| 6805 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6806 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6807 | } |
| 6808 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6809 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6810 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6811 | } finally { |
| 6812 | Binder.restoreCallingIdentity(identity); |
| 6813 | } |
| 6814 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6815 | |
| 6816 | /** |
| 6817 | * Scans for available networks. |
| 6818 | */ |
| 6819 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6820 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6821 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6823 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6824 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6825 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6826 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6827 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6828 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6829 | .setCallingPid(Binder.getCallingPid()) |
| 6830 | .setCallingUid(Binder.getCallingUid()) |
| 6831 | .setMethod("getCellNetworkScanResults") |
| 6832 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6833 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6834 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6835 | .build()); |
| 6836 | switch (locationResult) { |
| 6837 | case DENIED_HARD: |
| 6838 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6839 | case DENIED_SOFT: |
| 6840 | return null; |
| 6841 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6842 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6843 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6844 | try { |
| 6845 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6846 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6847 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6848 | } finally { |
| 6849 | Binder.restoreCallingIdentity(identity); |
| 6850 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6851 | } |
| 6852 | |
| 6853 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6854 | * Get the call forwarding info, given the call forwarding reason. |
| 6855 | */ |
| 6856 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6857 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6858 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6859 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6860 | |
| 6861 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6862 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6863 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6864 | long identity = Binder.clearCallingIdentity(); |
| 6865 | try { |
| 6866 | if (DBG) { |
| 6867 | log("getCallForwarding: subId " + subId |
| 6868 | + " callForwardingReason" + callForwardingReason); |
| 6869 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6870 | |
| 6871 | Phone phone = getPhone(subId); |
| 6872 | if (phone == null) { |
| 6873 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6874 | callback.onError( |
| 6875 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6876 | } catch (RemoteException e) { |
| 6877 | // ignore |
| 6878 | } |
| 6879 | return; |
| 6880 | } |
| 6881 | |
| 6882 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6883 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6884 | @Override |
| 6885 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6886 | try { |
| 6887 | callback.onCallForwardingInfoAvailable(info); |
| 6888 | } catch (RemoteException e) { |
| 6889 | // ignore |
| 6890 | } |
| 6891 | } |
| 6892 | |
| 6893 | @Override |
| 6894 | public void onError(int error) { |
| 6895 | try { |
| 6896 | callback.onError(error); |
| 6897 | } catch (RemoteException e) { |
| 6898 | // ignore |
| 6899 | } |
| 6900 | } |
| 6901 | }); |
| 6902 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6903 | } finally { |
| 6904 | Binder.restoreCallingIdentity(identity); |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | /** |
| 6909 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6910 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6911 | */ |
| 6912 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6913 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6914 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6915 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6916 | |
| 6917 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6918 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6919 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6920 | long identity = Binder.clearCallingIdentity(); |
| 6921 | try { |
| 6922 | if (DBG) { |
| 6923 | log("setCallForwarding: subId " + subId |
| 6924 | + " callForwardingInfo" + callForwardingInfo); |
| 6925 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6926 | |
| 6927 | Phone phone = getPhone(subId); |
| 6928 | if (phone == null) { |
| 6929 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6930 | callback.accept( |
| 6931 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6932 | } catch (RemoteException e) { |
| 6933 | // ignore |
| 6934 | } |
| 6935 | return; |
| 6936 | } |
| 6937 | |
| 6938 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6939 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6940 | |
| 6941 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6942 | } finally { |
| 6943 | Binder.restoreCallingIdentity(identity); |
| 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6948 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6949 | */ |
| 6950 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6951 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6952 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6953 | |
| 6954 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6955 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 6956 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6957 | long identity = Binder.clearCallingIdentity(); |
| 6958 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6959 | Phone phone = getPhone(subId); |
| 6960 | if (phone == null) { |
| 6961 | try { |
| 6962 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6963 | } catch (RemoteException e) { |
| 6964 | // ignore |
| 6965 | } |
| 6966 | return; |
| 6967 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6968 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6969 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6970 | boolean requireUssd = c.getBoolean( |
| 6971 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6972 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6973 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6974 | if (requireUssd) { |
| 6975 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6976 | getSubscriptionCarrierId(subId)); |
| 6977 | String newUssdCommand = ""; |
| 6978 | try { |
| 6979 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6980 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6981 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6982 | } catch (NullPointerException e) { |
| 6983 | loge("Failed to generate USSD number" + e); |
| 6984 | } |
| 6985 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6986 | mMainThreadHandler, callback, carrierXmlParser, |
| 6987 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6988 | final String ussdCommand = newUssdCommand; |
| 6989 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6990 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6991 | }); |
| 6992 | } else { |
| 6993 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6994 | callback::accept); |
| 6995 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6996 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6997 | } finally { |
| 6998 | Binder.restoreCallingIdentity(identity); |
| 6999 | } |
| 7000 | } |
| 7001 | |
| 7002 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7003 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7004 | */ |
| 7005 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7006 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7007 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7008 | |
| 7009 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7010 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7011 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7012 | long identity = Binder.clearCallingIdentity(); |
| 7013 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7014 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7015 | |
| 7016 | Phone phone = getPhone(subId); |
| 7017 | if (phone == null) { |
| 7018 | try { |
| 7019 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7020 | } catch (RemoteException e) { |
| 7021 | // ignore |
| 7022 | } |
| 7023 | return; |
| 7024 | } |
| 7025 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7026 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7027 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7028 | boolean requireUssd = c.getBoolean( |
| 7029 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7030 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7031 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7032 | if (requireUssd) { |
| 7033 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7034 | getSubscriptionCarrierId(subId)); |
| 7035 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7036 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7037 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7038 | String newUssdCommand = ""; |
| 7039 | try { |
| 7040 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7041 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7042 | .makeCommand(ssAction, null); |
| 7043 | } catch (NullPointerException e) { |
| 7044 | loge("Failed to generate USSD number" + e); |
| 7045 | } |
| 7046 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7047 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7048 | final String ussdCommand = newUssdCommand; |
| 7049 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7050 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7051 | }); |
| 7052 | } else { |
| 7053 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7054 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7055 | |
| 7056 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7057 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7058 | } finally { |
| 7059 | Binder.restoreCallingIdentity(identity); |
| 7060 | } |
| 7061 | } |
| 7062 | |
| 7063 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7064 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7065 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7066 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7067 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7068 | * location related information which will be sent if the caller already possess |
| 7069 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7070 | * @param request contains the radio access networks with bands/channels to scan |
| 7071 | * @param messenger callback messenger for scan results or errors |
| 7072 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7073 | * @return the id of the requested scan which can be used to stop the scan. |
| 7074 | */ |
| 7075 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7076 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7077 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7078 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7080 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7081 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7082 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7083 | if (!renounceFineLocationAccess) { |
| 7084 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7085 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7086 | .setCallingPackage(callingPackage) |
| 7087 | .setCallingFeatureId(callingFeatureId) |
| 7088 | .setCallingPid(Binder.getCallingPid()) |
| 7089 | .setCallingUid(Binder.getCallingUid()) |
| 7090 | .setMethod("requestNetworkScan") |
| 7091 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7092 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7093 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7094 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7095 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7096 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7097 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7098 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7099 | if (e != null) { |
| 7100 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7101 | throw e; |
| 7102 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7103 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7104 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7105 | } |
| 7106 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7107 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7108 | |
| 7109 | enforceTelephonyFeatureWithException(callingPackage, |
| 7110 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7111 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7112 | int callingUid = Binder.getCallingUid(); |
| 7113 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7114 | final long identity = Binder.clearCallingIdentity(); |
| 7115 | try { |
| 7116 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7117 | renounceFineLocationAccess, request, messenger, binder, |
| 7118 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7119 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7120 | } finally { |
| 7121 | Binder.restoreCallingIdentity(identity); |
| 7122 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7123 | } |
| 7124 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7125 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7126 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7127 | boolean hasCarrierPriv; |
| 7128 | final long identity = Binder.clearCallingIdentity(); |
| 7129 | try { |
| 7130 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7131 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7132 | } finally { |
| 7133 | Binder.restoreCallingIdentity(identity); |
| 7134 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7135 | boolean hasNetworkScanPermission = |
| 7136 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7137 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7138 | |
| 7139 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7140 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7141 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7145 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7146 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7147 | return new SecurityException("Specific channels must not be" |
| 7148 | + " scanned without location access."); |
| 7149 | } |
| 7150 | } |
| 7151 | } |
| 7152 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7153 | return null; |
| 7154 | } |
| 7155 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7156 | /** |
| 7157 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7158 | * |
| 7159 | * @param subId id of the subscription |
| 7160 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7161 | */ |
| 7162 | @Override |
| 7163 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7165 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7166 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7167 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7168 | final long identity = Binder.clearCallingIdentity(); |
| 7169 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7170 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | } finally { |
| 7172 | Binder.restoreCallingIdentity(identity); |
| 7173 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7174 | } |
| 7175 | |
| 7176 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7177 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7178 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7179 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7180 | */ |
| 7181 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7182 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7183 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7184 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7185 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7186 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7187 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7188 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7190 | final long identity = Binder.clearCallingIdentity(); |
| 7191 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7192 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7193 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7194 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7195 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7196 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | } finally { |
| 7198 | Binder.restoreCallingIdentity(identity); |
| 7199 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7200 | } |
| 7201 | |
| 7202 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7203 | * Get the allowed network types for certain reason. |
| 7204 | * |
| 7205 | * @param subId the id of the subscription. |
| 7206 | * @param reason the reason the allowed network type change is taking place |
| 7207 | * @return the allowed network types. |
| 7208 | */ |
| 7209 | @Override |
| 7210 | public long getAllowedNetworkTypesForReason(int subId, |
| 7211 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7212 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7213 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7214 | |
| 7215 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7216 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason"); |
| 7217 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7218 | final long identity = Binder.clearCallingIdentity(); |
| 7219 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7220 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7221 | } finally { |
| 7222 | Binder.restoreCallingIdentity(identity); |
| 7223 | } |
| 7224 | } |
| 7225 | |
| 7226 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7227 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7228 | * @param subId subscription id of the sim card |
| 7229 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7230 | * This can be passed following states |
| 7231 | * <ol> |
| 7232 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7233 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7234 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7235 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7236 | * </ol> |
| 7237 | * @return operation result. |
| 7238 | */ |
| 7239 | @Override |
| 7240 | public int setNrDualConnectivityState(int subId, |
| 7241 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7243 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7244 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7245 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7246 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7247 | } |
| 7248 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7249 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
| 7252 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7253 | nrDualConnectivityState, subId, |
| 7254 | workSource); |
| 7255 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7256 | return result; |
| 7257 | } finally { |
| 7258 | Binder.restoreCallingIdentity(identity); |
| 7259 | } |
| 7260 | } |
| 7261 | |
| 7262 | /** |
| 7263 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7264 | * @return true if dual connectivity is enabled else false |
| 7265 | */ |
| 7266 | @Override |
| 7267 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7268 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7269 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7270 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7271 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7272 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7273 | return false; |
| 7274 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7275 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7276 | final long identity = Binder.clearCallingIdentity(); |
| 7277 | try { |
| 7278 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7279 | null, subId, workSource); |
| 7280 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7281 | return isEnabled; |
| 7282 | } finally { |
| 7283 | Binder.restoreCallingIdentity(identity); |
| 7284 | } |
| 7285 | } |
| 7286 | |
| 7287 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7288 | * Set the allowed network types of the device and |
| 7289 | * provide the reason triggering the allowed network change. |
| 7290 | * |
| 7291 | * @param subId the id of the subscription. |
| 7292 | * @param reason the reason the allowed network type change is taking place |
| 7293 | * @param allowedNetworkTypes the allowed network types. |
| 7294 | * @return true on success; false on any failure. |
| 7295 | */ |
| 7296 | @Override |
| 7297 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7298 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7299 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7300 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7301 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7302 | // If the caller only has carrier privileges, then they should not be able to override |
| 7303 | // any network types which were set for security reasons. |
| 7304 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7305 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7306 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7307 | throw new SecurityException( |
| 7308 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7309 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7310 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7311 | |
| 7312 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7313 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7314 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7315 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7316 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7317 | return false; |
| 7318 | } |
| 7319 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7320 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7321 | return false; |
| 7322 | } |
| 7323 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7324 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7325 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7326 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7327 | Phone phone = getPhone(subId); |
| 7328 | if (phone == null) { |
| 7329 | return false; |
| 7330 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7331 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7332 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7333 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7334 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7335 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7336 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7337 | final long identity = Binder.clearCallingIdentity(); |
| 7338 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7339 | Boolean success = (Boolean) sendRequest( |
| 7340 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7341 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7342 | |
| 7343 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7344 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7345 | } finally { |
| 7346 | Binder.restoreCallingIdentity(identity); |
| 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7351 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7352 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7353 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7354 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7355 | * @hide |
| 7356 | */ |
| 7357 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7358 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7359 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7360 | |
| 7361 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7362 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7364 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7365 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7366 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7367 | if (phone != null) { |
| 7368 | return phone.hasMatchedTetherApnSetting(); |
| 7369 | } else { |
| 7370 | return false; |
| 7371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | } finally { |
| 7373 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7374 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7375 | } |
| 7376 | |
| 7377 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7378 | * Get the user enabled state of Mobile Data. |
| 7379 | * |
| 7380 | * TODO: remove and use isUserDataEnabled. |
| 7381 | * This can't be removed now because some vendor codes |
| 7382 | * calls through ITelephony directly while they should |
| 7383 | * use TelephonyManager. |
| 7384 | * |
| 7385 | * @return true on enabled |
| 7386 | */ |
| 7387 | @Override |
| 7388 | public boolean getDataEnabled(int subId) { |
| 7389 | return isUserDataEnabled(subId); |
| 7390 | } |
| 7391 | |
| 7392 | /** |
| 7393 | * Get whether mobile data is enabled per user setting. |
| 7394 | * |
| 7395 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7396 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7397 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7398 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7399 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7400 | * |
| 7401 | * @return {@code true} if data is enabled else {@code false} |
| 7402 | */ |
| 7403 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7404 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7405 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7406 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7407 | try { |
| 7408 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7409 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7410 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7411 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7412 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7413 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7414 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7415 | mApp, subId, functionName); |
| 7416 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7417 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7418 | |
| 7419 | final long identity = Binder.clearCallingIdentity(); |
| 7420 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7421 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7422 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7423 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7424 | if (phone != null) { |
| 7425 | boolean retVal = phone.isUserDataEnabled(); |
| 7426 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7427 | return retVal; |
| 7428 | } else { |
| 7429 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7430 | return false; |
| 7431 | } |
| 7432 | } finally { |
| 7433 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7434 | } |
| 7435 | } |
| 7436 | |
| 7437 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7438 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7439 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7440 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7441 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7442 | * @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] | 7443 | */ |
| 7444 | @Override |
| 7445 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7446 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7447 | try { |
| 7448 | try { |
| 7449 | mApp.enforceCallingOrSelfPermission( |
| 7450 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7451 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7452 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7453 | try { |
| 7454 | mApp.enforceCallingOrSelfPermission( |
| 7455 | android.Manifest.permission.READ_PHONE_STATE, |
| 7456 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7457 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7458 | mApp.enforceCallingOrSelfPermission( |
| 7459 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7460 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7461 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7462 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7463 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7464 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7466 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7467 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7469 | final long identity = Binder.clearCallingIdentity(); |
| 7470 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7471 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7472 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7473 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7474 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7475 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | return retVal; |
| 7477 | } else { |
| 7478 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7479 | return false; |
| 7480 | } |
| 7481 | } finally { |
| 7482 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7483 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7484 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7485 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7486 | /** |
| 7487 | * Check if data is enabled for a specific reason |
| 7488 | * @param subId Subscription index |
| 7489 | * @param reason the reason the data enable change is taking place |
| 7490 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7491 | */ |
| 7492 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7493 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7494 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7495 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7496 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7497 | try { |
| 7498 | mApp.enforceCallingOrSelfPermission( |
| 7499 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7500 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7501 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7502 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7503 | functionName); |
| 7504 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7505 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7506 | try { |
| 7507 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7508 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7509 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7510 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7511 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7512 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7513 | } |
| 7514 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7515 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7516 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7517 | |
| 7518 | final long identity = Binder.clearCallingIdentity(); |
| 7519 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7520 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7521 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7522 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7523 | + " reason=" + reason); |
| 7524 | } |
| 7525 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7526 | if (phone != null) { |
| 7527 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7528 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7529 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7530 | return retVal; |
| 7531 | } else { |
| 7532 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7533 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7534 | + subId + " retVal=false"); |
| 7535 | } |
| 7536 | return false; |
| 7537 | } |
| 7538 | } finally { |
| 7539 | Binder.restoreCallingIdentity(identity); |
| 7540 | } |
| 7541 | } |
| 7542 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7543 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7544 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7545 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7546 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7547 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7548 | // No permission needed; this only lets the caller inspect their own status. |
| 7549 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7550 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7551 | |
| 7552 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7553 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7554 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7555 | |
| 7556 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7557 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid"); |
| 7558 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7559 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7560 | } |
| 7561 | |
| 7562 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7563 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7564 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7565 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7566 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7567 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7568 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7569 | if (cpt == null) { |
| 7570 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7571 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7572 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7573 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7574 | } |
| 7575 | |
| 7576 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7577 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7578 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7579 | |
| 7580 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7581 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7582 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7583 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7584 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7585 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7586 | Phone phone = getPhone(subId); |
| 7587 | if (phone == null) { |
| 7588 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7589 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7590 | } |
| 7591 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7592 | if (cpt == null) { |
| 7593 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7594 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7595 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7596 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7597 | } |
| 7598 | |
| 7599 | @Override |
| 7600 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7601 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7602 | |
| 7603 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7604 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7605 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7606 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7607 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7608 | } |
| 7609 | |
| 7610 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7611 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7612 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7613 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7614 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7615 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7616 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7617 | if (phone == null) { |
| 7618 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7619 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7620 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7621 | if (cpt == null) { |
| 7622 | continue; |
| 7623 | } |
| 7624 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7625 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7626 | break; |
| 7627 | } |
| 7628 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7629 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7630 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7631 | |
| 7632 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7633 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7634 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7635 | |
| 7636 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7637 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7638 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7639 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7640 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7641 | if (phone == null) { |
| 7642 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7643 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7644 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7645 | if (cpt == null) { |
| 7646 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7647 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7648 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7649 | } |
| 7650 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7651 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7652 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7653 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7654 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7655 | if (phone == null) { |
| 7656 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7657 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7658 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7659 | if (cpt == null) { |
| 7660 | return Collections.emptyList(); |
| 7661 | } |
| 7662 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7663 | } |
| 7664 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7665 | @Override |
| 7666 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7667 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7668 | |
| 7669 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7670 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7671 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7672 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7673 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7674 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7675 | try { |
| 7676 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7677 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7678 | } |
| 7679 | } finally { |
| 7680 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7681 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7682 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7683 | } |
| 7684 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7685 | @Override |
| 7686 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7687 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7688 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7689 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7690 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7691 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7692 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7693 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7694 | if (phone == null) { |
| 7695 | return null; |
| 7696 | } |
| 7697 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7698 | if (cpt == null) { |
| 7699 | return null; |
| 7700 | } |
| 7701 | return cpt.getCarrierServicePackageName(); |
| 7702 | } |
| 7703 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7704 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7705 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7706 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7707 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7708 | return null; |
| 7709 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7710 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7711 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7712 | return null; |
| 7713 | } |
| 7714 | return iccId; |
| 7715 | } |
| 7716 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7717 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7718 | public void setCallComposerStatus(int subId, int status) { |
| 7719 | enforceModifyPermission(); |
| 7720 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7721 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7722 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7723 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7724 | final long identity = Binder.clearCallingIdentity(); |
| 7725 | try { |
| 7726 | Phone phone = getPhone(subId); |
| 7727 | if (phone != null) { |
| 7728 | Phone defaultPhone = phone.getImsPhone(); |
| 7729 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7730 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7731 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7732 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7733 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7734 | } |
| 7735 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7736 | } catch (ImsException e) { |
| 7737 | throw new ServiceSpecificException(e.getCode()); |
| 7738 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7739 | Binder.restoreCallingIdentity(identity); |
| 7740 | } |
| 7741 | } |
| 7742 | |
| 7743 | @Override |
| 7744 | public int getCallComposerStatus(int subId) { |
| 7745 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7746 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7747 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7748 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7749 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7750 | final long identity = Binder.clearCallingIdentity(); |
| 7751 | try { |
| 7752 | Phone phone = getPhone(subId); |
| 7753 | if (phone != null) { |
| 7754 | Phone defaultPhone = phone.getImsPhone(); |
| 7755 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7756 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7757 | return imsPhone.getCallComposerStatus(); |
| 7758 | } |
| 7759 | } |
| 7760 | } finally { |
| 7761 | Binder.restoreCallingIdentity(identity); |
| 7762 | } |
| 7763 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7764 | } |
| 7765 | |
| 7766 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7767 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7768 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7769 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7770 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7771 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7772 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7773 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7774 | "setLine1NumberForDisplayForSubscriber"); |
| 7775 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7776 | final long identity = Binder.clearCallingIdentity(); |
| 7777 | try { |
| 7778 | final String iccId = getIccId(subId); |
| 7779 | final Phone phone = getPhone(subId); |
| 7780 | if (phone == null) { |
| 7781 | return false; |
| 7782 | } |
| 7783 | final String subscriberId = phone.getSubscriberId(); |
| 7784 | |
| 7785 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7786 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7787 | + subscriberId + " to " + number); |
| 7788 | } |
| 7789 | |
| 7790 | if (TextUtils.isEmpty(iccId)) { |
| 7791 | return false; |
| 7792 | } |
| 7793 | |
| 7794 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7795 | |
| 7796 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7797 | if (alphaTag == null) { |
| 7798 | editor.remove(alphaTagPrefKey); |
| 7799 | } else { |
| 7800 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7801 | } |
| 7802 | |
| 7803 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7804 | // track all merged IMSIs based on line number |
| 7805 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7806 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7807 | if (number == null) { |
| 7808 | editor.remove(numberPrefKey); |
| 7809 | editor.remove(subscriberPrefKey); |
| 7810 | } else { |
| 7811 | editor.putString(numberPrefKey, number); |
| 7812 | editor.putString(subscriberPrefKey, subscriberId); |
| 7813 | } |
| 7814 | |
| 7815 | editor.commit(); |
| 7816 | return true; |
| 7817 | } finally { |
| 7818 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7819 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7820 | } |
| 7821 | |
| 7822 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7823 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7824 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7825 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7826 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7827 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7828 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7829 | return null; |
| 7830 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7831 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7832 | enforceTelephonyFeatureWithException(callingPackage, |
| 7833 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7834 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7835 | final long identity = Binder.clearCallingIdentity(); |
| 7836 | try { |
| 7837 | String iccId = getIccId(subId); |
| 7838 | if (iccId != null) { |
| 7839 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7840 | if (DBG_MERGE) { |
| 7841 | log("getLine1NumberForDisplay returning " |
| 7842 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7843 | } |
| 7844 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7845 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7846 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7847 | return null; |
| 7848 | } finally { |
| 7849 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7850 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7851 | } |
| 7852 | |
| 7853 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7854 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7855 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7856 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7857 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7858 | return null; |
| 7859 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7860 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7861 | final long identity = Binder.clearCallingIdentity(); |
| 7862 | try { |
| 7863 | String iccId = getIccId(subId); |
| 7864 | if (iccId != null) { |
| 7865 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7866 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7867 | } |
| 7868 | return null; |
| 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7871 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7872 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7873 | |
| 7874 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7875 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7876 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7877 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7878 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7879 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7880 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7881 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7882 | return null; |
| 7883 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7884 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7885 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7886 | // the process, where TelephonyManager was instantiated. |
| 7887 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7888 | final long identity = Binder.clearCallingIdentity(); |
| 7889 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7890 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7891 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7892 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7893 | |
| 7894 | // Figure out what subscribers are currently active |
| 7895 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7896 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7897 | // Only consider subs which match the current subId |
| 7898 | // This logic can be simplified. See b/131189269 for progress. |
| 7899 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7900 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7901 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7902 | |
| 7903 | // First pass, find a number override for an active subscriber |
| 7904 | String mergeNumber = null; |
| 7905 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7906 | for (String key : prefs.keySet()) { |
| 7907 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7908 | final String subscriberId = (String) prefs.get(key); |
| 7909 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7910 | final String iccId = key.substring( |
| 7911 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7912 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7913 | mergeNumber = (String) prefs.get(numberKey); |
| 7914 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7915 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7916 | + " for active subscriber " + subscriberId); |
| 7917 | } |
| 7918 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7919 | break; |
| 7920 | } |
| 7921 | } |
| 7922 | } |
| 7923 | } |
| 7924 | |
| 7925 | // Shortcut when no active merged subscribers |
| 7926 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7927 | return null; |
| 7928 | } |
| 7929 | |
| 7930 | // Second pass, find all subscribers under that line override |
| 7931 | final ArraySet<String> result = new ArraySet<>(); |
| 7932 | for (String key : prefs.keySet()) { |
| 7933 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7934 | final String number = (String) prefs.get(key); |
| 7935 | if (mergeNumber.equals(number)) { |
| 7936 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7937 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7938 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7939 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7940 | result.add(subscriberId); |
| 7941 | } |
| 7942 | } |
| 7943 | } |
| 7944 | } |
| 7945 | |
| 7946 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7947 | Arrays.sort(resultArray); |
| 7948 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7949 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7950 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7951 | } |
| 7952 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7953 | } finally { |
| 7954 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7955 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7956 | } |
| 7957 | |
| 7958 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7959 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7960 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7961 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7962 | enforceTelephonyFeatureWithException(callingPackage, |
| 7963 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 7964 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7965 | final long identity = Binder.clearCallingIdentity(); |
| 7966 | try { |
| 7967 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7968 | TelephonyManager.class); |
| 7969 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7970 | if (subscriberId == null) { |
| 7971 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7972 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7973 | + subId); |
| 7974 | } |
| 7975 | return null; |
| 7976 | } |
| 7977 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7978 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 7979 | .getSubscriptionInfo(subId); |
| 7980 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7981 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7982 | if (groupUuid == null) { |
| 7983 | return new String[]{subscriberId}; |
| 7984 | } |
| 7985 | |
| 7986 | // Get all subscriberIds from the group. |
| 7987 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 7988 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 7989 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7990 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7991 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7992 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7993 | if (subscriberId != null) { |
| 7994 | mergedSubscriberIds.add(subscriberId); |
| 7995 | } |
| 7996 | } |
| 7997 | |
| 7998 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7999 | } finally { |
| 8000 | Binder.restoreCallingIdentity(identity); |
| 8001 | |
| 8002 | } |
| 8003 | } |
| 8004 | |
| 8005 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8006 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8007 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8008 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8009 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8010 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8011 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8013 | final long identity = Binder.clearCallingIdentity(); |
| 8014 | try { |
| 8015 | final Phone phone = getPhone(subId); |
| 8016 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8017 | } finally { |
| 8018 | Binder.restoreCallingIdentity(identity); |
| 8019 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8020 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8021 | |
| 8022 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8023 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8024 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8025 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8026 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8027 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8028 | |
| 8029 | final long identity = Binder.clearCallingIdentity(); |
| 8030 | try { |
| 8031 | final Phone phone = getPhone(subId); |
| 8032 | if (phone == null) { |
| 8033 | return false; |
| 8034 | } |
| 8035 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8036 | cdmaNonRoamingList); |
| 8037 | } finally { |
| 8038 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8039 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8040 | } |
| 8041 | |
| 8042 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8043 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8044 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8045 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8046 | if (phone == null) { |
| 8047 | return raf; |
| 8048 | } |
| 8049 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8050 | try { |
| 8051 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8052 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8053 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8054 | } catch (SecurityException e) { |
| 8055 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8056 | throw e; |
| 8057 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8058 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8059 | enforceTelephonyFeatureWithException(callingPackage, |
| 8060 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8061 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8062 | final long identity = Binder.clearCallingIdentity(); |
| 8063 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8064 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8065 | } finally { |
| 8066 | Binder.restoreCallingIdentity(identity); |
| 8067 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8068 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8069 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8070 | |
| 8071 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8072 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8073 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8074 | try { |
| 8075 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 8076 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8077 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8078 | } |
| 8079 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 8080 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8081 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8082 | |
| 8083 | enforceTelephonyFeatureWithException(callingPackage, |
| 8084 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8085 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8086 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 8087 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 8088 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8089 | throw new SecurityException("App must be the dialer role holder to" |
| 8090 | + " upload a call composer pic"); |
| 8091 | } |
| 8092 | |
| 8093 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8094 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8095 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8096 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8097 | boolean readUntilEnd = false; |
| 8098 | int totalBytesRead = 0; |
| 8099 | byte[] buffer = new byte[16 * 1024]; |
| 8100 | while (true) { |
| 8101 | int numRead; |
| 8102 | try { |
| 8103 | numRead = input.read(buffer); |
| 8104 | } catch (IOException e) { |
| 8105 | try { |
| 8106 | fd.checkError(); |
| 8107 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8108 | null); |
| 8109 | } catch (IOException e1) { |
| 8110 | // This means that the other side closed explicitly with an error. If this |
| 8111 | // happens, log and ignore. |
| 8112 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8113 | } |
| 8114 | break; |
| 8115 | } |
| 8116 | if (numRead == -1) { |
| 8117 | readUntilEnd = true; |
| 8118 | break; |
| 8119 | } |
| 8120 | totalBytesRead += numRead; |
| 8121 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8122 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8123 | try { |
| 8124 | input.close(); |
| 8125 | } catch (IOException e) { |
| 8126 | // ignore |
| 8127 | } |
| 8128 | break; |
| 8129 | } |
| 8130 | output.write(buffer, 0, numRead); |
| 8131 | } |
| 8132 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8133 | // close is above, where the picture size is too big. |
| 8134 | |
| 8135 | try { |
| 8136 | fd.checkError(); |
| 8137 | } catch (IOException e) { |
| 8138 | loge("Remote end for call composer closed with an error: " + e); |
| 8139 | return; |
| 8140 | } |
| 8141 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8142 | if (!readUntilEnd) { |
| 8143 | loge("Did not finish reading entire image; aborting"); |
| 8144 | return; |
| 8145 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8146 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8147 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8148 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8149 | new CallComposerPictureTransfer.Factory() {}, |
| 8150 | imageData, |
| 8151 | (result) -> { |
| 8152 | if (result.first != null) { |
| 8153 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8154 | Bundle outputResult = new Bundle(); |
| 8155 | outputResult.putParcelable( |
| 8156 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8157 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8158 | outputResult); |
| 8159 | } else { |
| 8160 | callback.send(result.second, null); |
| 8161 | } |
| 8162 | } |
| 8163 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8164 | }); |
| 8165 | } |
| 8166 | |
| 8167 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8168 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8169 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8170 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8171 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8172 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8173 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8174 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8175 | final long identity = Binder.clearCallingIdentity(); |
| 8176 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8177 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8178 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8179 | } finally { |
| 8180 | Binder.restoreCallingIdentity(identity); |
| 8181 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8182 | } |
| 8183 | |
| 8184 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8185 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8186 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8187 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8188 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8189 | return false; |
| 8190 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8191 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8192 | enforceTelephonyFeatureWithException(callingPackage, |
| 8193 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8194 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8195 | final long identity = Binder.clearCallingIdentity(); |
| 8196 | try { |
| 8197 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8198 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8199 | // In the long run, we may instead need to check if there exists a connection service |
| 8200 | // which can support video calling. |
| 8201 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8202 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8203 | return imsManager.isVtEnabledByPlatform() |
| 8204 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8205 | && imsManager.isVtEnabledByUser(); |
| 8206 | } finally { |
| 8207 | Binder.restoreCallingIdentity(identity); |
| 8208 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8209 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8210 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8211 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8212 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8213 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8215 | mApp, subId, callingPackage, callingFeatureId, |
| 8216 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8217 | return false; |
| 8218 | } |
| 8219 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8220 | enforceTelephonyFeatureWithException(callingPackage, |
| 8221 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8223 | final long identity = Binder.clearCallingIdentity(); |
| 8224 | try { |
| 8225 | CarrierConfigManager configManager = |
| 8226 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8227 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8228 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8229 | } finally { |
| 8230 | Binder.restoreCallingIdentity(identity); |
| 8231 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8232 | } |
| 8233 | |
| 8234 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8235 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8236 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8237 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8238 | return false; |
| 8239 | } |
| 8240 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8241 | enforceTelephonyFeatureWithException(callingPackage, |
| 8242 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8243 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8244 | final long identity = Binder.clearCallingIdentity(); |
| 8245 | try { |
| 8246 | CarrierConfigManager configManager = |
| 8247 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8248 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8249 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8250 | } finally { |
| 8251 | Binder.restoreCallingIdentity(identity); |
| 8252 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8253 | } |
| 8254 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8255 | @Override |
| 8256 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8257 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8258 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8259 | } |
| 8260 | |
| 8261 | @Override |
| 8262 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8263 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8264 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8265 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8266 | final long identity = Binder.clearCallingIdentity(); |
| 8267 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8268 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8269 | } finally { |
| 8270 | Binder.restoreCallingIdentity(identity); |
| 8271 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8272 | } |
| 8273 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8274 | /** |
| 8275 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8276 | * support for the feature and device firmware support. |
| 8277 | * |
| 8278 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8279 | */ |
| 8280 | @Override |
| 8281 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8282 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8283 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8284 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8285 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8286 | final Phone phone = getPhone(subscriptionId); |
| 8287 | if (phone == null) { |
| 8288 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8289 | return false; |
| 8290 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8292 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8294 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8295 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8296 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8297 | return isCarrierSupported && isDeviceSupported; |
| 8298 | } finally { |
| 8299 | Binder.restoreCallingIdentity(identity); |
| 8300 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8301 | } |
| 8302 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8303 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8304 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8305 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8306 | * 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] | 8307 | */ |
| 8308 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8309 | final long identity = Binder.clearCallingIdentity(); |
| 8310 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8311 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8312 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8313 | return false; |
| 8314 | } |
| 8315 | } |
| 8316 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8317 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8318 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8319 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8320 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8321 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8322 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8323 | } finally { |
| 8324 | Binder.restoreCallingIdentity(identity); |
| 8325 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8326 | } |
| 8327 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8328 | @Deprecated |
| 8329 | @Override |
| 8330 | public String getDeviceId(String callingPackage) { |
| 8331 | return getDeviceIdWithFeature(callingPackage, null); |
| 8332 | } |
| 8333 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8334 | /** |
| 8335 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8336 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8337 | * |
| 8338 | * <p>Requires Permission: |
| 8339 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8340 | */ |
| 8341 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8342 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8343 | try { |
| 8344 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8345 | } catch (SecurityException se) { |
| 8346 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8347 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8348 | + Binder.getCallingUid()); |
| 8349 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8350 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8351 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8352 | return null; |
| 8353 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8354 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8355 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8356 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8357 | return null; |
| 8358 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8359 | |
| 8360 | final long identity = Binder.clearCallingIdentity(); |
| 8361 | try { |
| 8362 | return phone.getDeviceId(); |
| 8363 | } finally { |
| 8364 | Binder.restoreCallingIdentity(identity); |
| 8365 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8366 | } |
| 8367 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8368 | /** |
| 8369 | * {@hide} |
| 8370 | * Returns the IMS Registration Status on a particular subid |
| 8371 | * |
| 8372 | * @param subId |
| 8373 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8374 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8375 | Phone phone = getPhone(subId); |
| 8376 | if (phone != null) { |
| 8377 | return phone.isImsRegistered(); |
| 8378 | } else { |
| 8379 | return false; |
| 8380 | } |
| 8381 | } |
| 8382 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8383 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8384 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8385 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8386 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8387 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8388 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8389 | } |
| 8390 | final long identity = Binder.clearCallingIdentity(); |
| 8391 | try { |
| 8392 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
| 8395 | } |
| 8396 | } |
| 8397 | |
| 8398 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8399 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8400 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8401 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8402 | mApp, |
| 8403 | subscriptionId, |
| 8404 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8405 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8406 | |
| 8407 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8408 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8409 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8410 | final long identity = Binder.clearCallingIdentity(); |
| 8411 | try { |
| 8412 | Phone phone = getPhone(subscriptionId); |
| 8413 | if (phone == null) { |
| 8414 | return null; |
| 8415 | } |
| 8416 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8417 | } finally { |
| 8418 | Binder.restoreCallingIdentity(identity); |
| 8419 | } |
| 8420 | } |
| 8421 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8422 | /** |
| 8423 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8424 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8425 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8426 | final long identity = Binder.clearCallingIdentity(); |
| 8427 | try { |
| 8428 | Phone phone = getPhone(subId); |
| 8429 | if (phone != null) { |
| 8430 | return phone.isWifiCallingEnabled(); |
| 8431 | } else { |
| 8432 | return false; |
| 8433 | } |
| 8434 | } finally { |
| 8435 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8436 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8437 | } |
| 8438 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8439 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8440 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8441 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8442 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8443 | final long identity = Binder.clearCallingIdentity(); |
| 8444 | try { |
| 8445 | Phone phone = getPhone(subId); |
| 8446 | if (phone != null) { |
| 8447 | return phone.isVideoEnabled(); |
| 8448 | } else { |
| 8449 | return false; |
| 8450 | } |
| 8451 | } finally { |
| 8452 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8453 | } |
| 8454 | } |
| 8455 | |
| 8456 | /** |
| 8457 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8458 | * defined in {@link ImsRegistrationImplBase}. |
| 8459 | */ |
| 8460 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8461 | final long identity = Binder.clearCallingIdentity(); |
| 8462 | try { |
| 8463 | Phone phone = getPhone(subId); |
| 8464 | if (phone != null) { |
| 8465 | return phone.getImsRegistrationTech(); |
| 8466 | } else { |
| 8467 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8468 | } |
| 8469 | } finally { |
| 8470 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8471 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8472 | } |
| 8473 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8474 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8475 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8476 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8477 | |
| 8478 | enforceTelephonyFeatureWithException(callingPackage, |
| 8479 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8480 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8481 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8482 | return; |
| 8483 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8484 | Phone defaultPhone = getDefaultPhone(); |
| 8485 | if (defaultPhone != null) { |
| 8486 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8487 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8488 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8489 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8490 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8491 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8492 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8493 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8494 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8495 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8496 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8497 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8498 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8499 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8500 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8501 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8502 | // There has been issues when Sms raw table somehow stores orphan |
| 8503 | // fragments. They lead to garbled message when new fragments come |
| 8504 | // in and combined with those stale ones. In case this happens again, |
| 8505 | // user can reset all network settings which will clean up this table. |
| 8506 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8507 | // Clean up IMS settings as well here. |
| 8508 | int slotId = getSlotIndex(subId); |
| 8509 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8510 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8511 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8512 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8513 | if (defaultPhone == null) { |
| 8514 | return; |
| 8515 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8516 | // Erase modem config if erase modem on network setting is enabled. |
| 8517 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8518 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8519 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8520 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8521 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8522 | |
| 8523 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8524 | } finally { |
| 8525 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8526 | } |
| 8527 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8528 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8529 | @VisibleForTesting |
| 8530 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8531 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8532 | return; |
| 8533 | } |
| 8534 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8535 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8536 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8537 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8538 | "user=" + defaultNetworkType); |
| 8539 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8540 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8541 | defaultNetworkType, null); |
| 8542 | } |
| 8543 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8544 | private void cleanUpSmsRawTable(Context context) { |
| 8545 | ContentResolver resolver = context.getContentResolver(); |
| 8546 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8547 | resolver.delete(uri, null, null); |
| 8548 | } |
| 8549 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8550 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8551 | public String getSimLocaleForSubscriber(int subId) { |
| 8552 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8553 | |
| 8554 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8555 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8556 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8557 | final Phone phone = getPhone(subId); |
| 8558 | if (phone == null) { |
| 8559 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8560 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8561 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8562 | final long identity = Binder.clearCallingIdentity(); |
| 8563 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8564 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8565 | phone.getContext().getOpPackageName(), |
| 8566 | phone.getContext().getAttributionTag()); |
| 8567 | if (info == null) { |
| 8568 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8569 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8572 | // preferences (EF-PL and EF-LI)... |
| 8573 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8574 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8575 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8576 | if (localeFromDefaultSim != null) { |
| 8577 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8578 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8579 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8580 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8581 | } else { |
| 8582 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8583 | } |
| 8584 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8585 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8586 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8587 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8588 | // the SIM and carrier preferences does not include a country we add the country |
| 8589 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8590 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8591 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8592 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8593 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8594 | } |
| 8595 | |
| 8596 | if (DBG) log("No locale found - returning null"); |
| 8597 | return null; |
| 8598 | } finally { |
| 8599 | Binder.restoreCallingIdentity(identity); |
| 8600 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8601 | } |
| 8602 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8603 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8604 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8605 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8606 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8607 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8608 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8609 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8610 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8611 | return localeTag; |
| 8612 | } |
| 8613 | } |
| 8614 | return inputLocale.toLanguageTag(); |
| 8615 | } |
| 8616 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8617 | /** |
| 8618 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8619 | */ |
| 8620 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8621 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8622 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8623 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8624 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8625 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8626 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8627 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8628 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8629 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8630 | * representing the state of the modem. |
| 8631 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8632 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8633 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8634 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8635 | */ |
| 8636 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8637 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8638 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8639 | |
| 8640 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8641 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8642 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8643 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8644 | |
| 8645 | final long identity = Binder.clearCallingIdentity(); |
| 8646 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8647 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8648 | } finally { |
| 8649 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8650 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8651 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8652 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8653 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8654 | // less than total activity duration. |
| 8655 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8656 | if (info == null) { |
| 8657 | return false; |
| 8658 | } |
| 8659 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8660 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8661 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8662 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8663 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8664 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8665 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8666 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8667 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8668 | } |
| 8669 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8670 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8671 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8672 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8673 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8674 | |
| 8675 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8676 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8677 | } |
| 8678 | |
| 8679 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8680 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8681 | rat, |
| 8682 | freq, |
| 8683 | info.getReceiveTimeMillis(rat, freq) |
| 8684 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8685 | } |
| 8686 | |
| 8687 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8688 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8689 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8690 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8691 | |
| 8692 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8693 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8694 | } |
| 8695 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8696 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8697 | rat, |
| 8698 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8699 | } |
| 8700 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8701 | /** |
| 8702 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8703 | * @param info recent ModemActivityInfo |
| 8704 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8705 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8706 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8707 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8708 | boolean matched; |
| 8709 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8710 | matched = false; |
| 8711 | int rat = info.getSpecificInfoRat(i); |
| 8712 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8713 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8714 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8715 | //if it already exists |
| 8716 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8717 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8718 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8719 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8720 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8721 | updateLastModemActivityInfo(info, rat, freq); |
| 8722 | matched = true; |
| 8723 | } |
| 8724 | } else { |
| 8725 | updateLastModemActivityInfo(info, rat); |
| 8726 | matched = true; |
| 8727 | } |
| 8728 | } |
| 8729 | } |
| 8730 | |
| 8731 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8732 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8733 | new ActivityStatsTechSpecificInfo( |
| 8734 | rat, |
| 8735 | freq, |
| 8736 | info.getTransmitTimeMillis(rat, freq), |
| 8737 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8738 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8739 | } |
| 8740 | } |
| 8741 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8742 | mLastModemActivitySpecificInfo = |
| 8743 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8744 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8745 | |
| 8746 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8747 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8748 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8749 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8750 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8751 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8752 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8753 | |
| 8754 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8755 | new ModemActivityInfo( |
| 8756 | mLastModemActivityInfo.getTimestampMillis(), |
| 8757 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8758 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8759 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8760 | } |
| 8761 | |
| 8762 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8763 | ActivityStatsTechSpecificInfo[] info) { |
| 8764 | int infoSize = info.length; |
| 8765 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8766 | for (int i = 0; i < infoSize; i++) { |
| 8767 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8768 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8769 | info[i].getTransmitTimeMillis(), |
| 8770 | (int) info[i].getReceiveTimeMillis()); |
| 8771 | } |
| 8772 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8773 | } |
| 8774 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8775 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8776 | * Returns the service state information on specified subscription. |
| 8777 | */ |
| 8778 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8779 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8780 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8781 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8782 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8783 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8784 | return null; |
| 8785 | } |
| 8786 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8787 | enforceTelephonyFeatureWithException(callingPackage, |
| 8788 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8789 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8790 | boolean hasFinePermission = false; |
| 8791 | boolean hasCoarsePermission = false; |
| 8792 | if (!renounceFineLocationAccess) { |
| 8793 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8794 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8795 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8796 | .setCallingPackage(callingPackage) |
| 8797 | .setCallingFeatureId(callingFeatureId) |
| 8798 | .setCallingPid(Binder.getCallingPid()) |
| 8799 | .setCallingUid(Binder.getCallingUid()) |
| 8800 | .setMethod("getServiceStateForSubscriber") |
| 8801 | .setLogAsInfo(true) |
| 8802 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8803 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8804 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8805 | .build()); |
| 8806 | hasFinePermission = |
| 8807 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8808 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8809 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8810 | if (!renounceCoarseLocationAccess) { |
| 8811 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8812 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8813 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8814 | .setCallingPackage(callingPackage) |
| 8815 | .setCallingFeatureId(callingFeatureId) |
| 8816 | .setCallingPid(Binder.getCallingPid()) |
| 8817 | .setCallingUid(Binder.getCallingUid()) |
| 8818 | .setMethod("getServiceStateForSubscriber") |
| 8819 | .setLogAsInfo(true) |
| 8820 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8821 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8822 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8823 | .build()); |
| 8824 | hasCoarsePermission = |
| 8825 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8826 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8827 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8828 | final Phone phone = getPhone(subId); |
| 8829 | if (phone == null) { |
| 8830 | return null; |
| 8831 | } |
| 8832 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8833 | final long identity = Binder.clearCallingIdentity(); |
| 8834 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8835 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8836 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8837 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8838 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8839 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8840 | .getSubscriptionInfoInternal(subId); |
| 8841 | if (subInfo == null || !subInfo.isActive()) { |
| 8842 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8843 | + "subId=" + subId); |
| 8844 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8845 | } |
| 8846 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8847 | ServiceState ss = phone.getServiceState(); |
| 8848 | |
| 8849 | // Scrub out the location info in ServiceState depending on what level of access |
| 8850 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8851 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8852 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8853 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8854 | } finally { |
| 8855 | Binder.restoreCallingIdentity(identity); |
| 8856 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8857 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8858 | |
| 8859 | /** |
| 8860 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8861 | * |
| 8862 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8863 | * voicemail ringtone. |
| 8864 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8865 | * PhoneAccount. |
| 8866 | */ |
| 8867 | @Override |
| 8868 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8869 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8870 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8871 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8872 | final long identity = Binder.clearCallingIdentity(); |
| 8873 | try { |
| 8874 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8875 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8876 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8877 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8879 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8880 | } finally { |
| 8881 | Binder.restoreCallingIdentity(identity); |
| 8882 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8883 | } |
| 8884 | |
| 8885 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8886 | * Sets the per-account voicemail ringtone. |
| 8887 | * |
| 8888 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8889 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8890 | * |
| 8891 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8892 | * voicemail ringtone. |
| 8893 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8894 | * PhoneAccount. |
| 8895 | */ |
| 8896 | @Override |
| 8897 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8898 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8899 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8900 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8901 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8902 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8903 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8904 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8905 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8907 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8908 | enforceTelephonyFeatureWithException(callingPackage, |
| 8909 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 8910 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8911 | final long identity = Binder.clearCallingIdentity(); |
| 8912 | try { |
| 8913 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8914 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8915 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8916 | } |
| 8917 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8918 | } finally { |
| 8919 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8920 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8921 | } |
| 8922 | |
| 8923 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8924 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8925 | * |
| 8926 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8927 | * voicemail vibration setting. |
| 8928 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8929 | */ |
| 8930 | @Override |
| 8931 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8932 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8933 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 8934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8935 | final long identity = Binder.clearCallingIdentity(); |
| 8936 | try { |
| 8937 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8938 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8939 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8940 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8941 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8942 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8943 | } finally { |
| 8944 | Binder.restoreCallingIdentity(identity); |
| 8945 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8946 | } |
| 8947 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8948 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8949 | * Sets the per-account voicemail vibration. |
| 8950 | * |
| 8951 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8952 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8953 | * |
| 8954 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8955 | * voicemail vibration setting. |
| 8956 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8957 | * specific PhoneAccount. |
| 8958 | */ |
| 8959 | @Override |
| 8960 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8961 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8962 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8963 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8964 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8965 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8967 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8968 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8969 | } |
| 8970 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8971 | enforceTelephonyFeatureWithException(callingPackage, |
| 8972 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 8973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8974 | final long identity = Binder.clearCallingIdentity(); |
| 8975 | try { |
| 8976 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8977 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8978 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8979 | } |
| 8980 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8981 | } finally { |
| 8982 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8983 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8984 | } |
| 8985 | |
| 8986 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8987 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8988 | * |
| 8989 | * @throws SecurityException if the caller does not have the required permission |
| 8990 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8991 | @VisibleForTesting |
| 8992 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8993 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8994 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8995 | } |
| 8996 | |
| 8997 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8998 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8999 | * permission. |
| 9000 | * |
| 9001 | * @throws SecurityException if the caller does not have the required permission |
| 9002 | */ |
| 9003 | private void enforceSendSmsPermission() { |
| 9004 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9005 | } |
| 9006 | |
| 9007 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9008 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9009 | * users permission. |
| 9010 | * |
| 9011 | * @throws SecurityException if the caller does not have the required permission |
| 9012 | */ |
| 9013 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9014 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9015 | } |
| 9016 | |
| 9017 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9018 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9019 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9020 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9021 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9022 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9023 | final long identity = Binder.clearCallingIdentity(); |
| 9024 | try { |
| 9025 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9026 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9027 | if (componentName == null) { |
| 9028 | throw new SecurityException( |
| 9029 | "Caller not current active visual voicemail package[null]"); |
| 9030 | } |
| 9031 | String vvmPackage = componentName.getPackageName(); |
| 9032 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9033 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9034 | } |
| 9035 | } finally { |
| 9036 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9037 | } |
| 9038 | } |
| 9039 | |
| 9040 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9041 | * Return the application ID for the app type. |
| 9042 | * |
| 9043 | * @param subId the subscription ID that this request applies to. |
| 9044 | * @param appType the uicc app type. |
| 9045 | * @return Application ID for specificied app type, or null if no uicc. |
| 9046 | */ |
| 9047 | @Override |
| 9048 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9049 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9050 | |
| 9051 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9052 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9053 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9054 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9055 | |
| 9056 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9057 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9058 | if (phone == null) { |
| 9059 | return null; |
| 9060 | } |
| 9061 | String aid = null; |
| 9062 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9063 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9064 | .getApplicationByType(appType).getAid(); |
| 9065 | } catch (Exception e) { |
| 9066 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9067 | } |
| 9068 | return aid; |
| 9069 | } finally { |
| 9070 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9071 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9072 | } |
| 9073 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9074 | /** |
| 9075 | * Return the Electronic Serial Number. |
| 9076 | * |
| 9077 | * @param subId the subscription ID that this request applies to. |
| 9078 | * @return ESN or null if error. |
| 9079 | */ |
| 9080 | @Override |
| 9081 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9082 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9083 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9084 | |
| 9085 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9086 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9087 | if (phone == null) { |
| 9088 | return null; |
| 9089 | } |
| 9090 | String esn = null; |
| 9091 | try { |
| 9092 | esn = phone.getEsn(); |
| 9093 | } catch (Exception e) { |
| 9094 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9095 | } |
| 9096 | return esn; |
| 9097 | } finally { |
| 9098 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9099 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9100 | } |
| 9101 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9102 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9103 | * Return the Preferred Roaming List Version. |
| 9104 | * |
| 9105 | * @param subId the subscription ID that this request applies to. |
| 9106 | * @return PRLVersion or null if error. |
| 9107 | */ |
| 9108 | @Override |
| 9109 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9110 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9111 | |
| 9112 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9113 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9114 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9115 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9116 | |
| 9117 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9118 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9119 | if (phone == null) { |
| 9120 | return null; |
| 9121 | } |
| 9122 | String cdmaPrlVersion = null; |
| 9123 | try { |
| 9124 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9125 | } catch (Exception e) { |
| 9126 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9127 | } |
| 9128 | return cdmaPrlVersion; |
| 9129 | } finally { |
| 9130 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9131 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9132 | } |
| 9133 | |
| 9134 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9135 | * Get snapshot of Telephony histograms |
| 9136 | * @return List of Telephony histograms |
| 9137 | * @hide |
| 9138 | */ |
| 9139 | @Override |
| 9140 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9141 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9142 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9143 | |
| 9144 | final long identity = Binder.clearCallingIdentity(); |
| 9145 | try { |
| 9146 | return RIL.getTelephonyRILTimingHistograms(); |
| 9147 | } finally { |
| 9148 | Binder.restoreCallingIdentity(identity); |
| 9149 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9150 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9151 | |
| 9152 | /** |
| 9153 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9154 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9155 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9156 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9157 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9158 | * @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] | 9159 | */ |
| 9160 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9161 | @TelephonyManager.SetCarrierRestrictionResult |
| 9162 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9163 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9164 | |
| 9165 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9166 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9167 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9168 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9169 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9170 | if (carrierRestrictionRules == null) { |
| 9171 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9172 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9173 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9174 | final long identity = Binder.clearCallingIdentity(); |
| 9175 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9176 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9177 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9178 | } finally { |
| 9179 | Binder.restoreCallingIdentity(identity); |
| 9180 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9181 | } |
| 9182 | |
| 9183 | /** |
| 9184 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9185 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9186 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9187 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9188 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9189 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9190 | */ |
| 9191 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9192 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9193 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9194 | |
| 9195 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9196 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9197 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9198 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9199 | |
| 9200 | final long identity = Binder.clearCallingIdentity(); |
| 9201 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9202 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9203 | if (response instanceof CarrierRestrictionRules) { |
| 9204 | return (CarrierRestrictionRules) response; |
| 9205 | } |
| 9206 | // Response is an Exception of some kind, |
| 9207 | // which is signalled to the user as a NULL retval |
| 9208 | return null; |
| 9209 | } catch (Exception e) { |
| 9210 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9211 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9212 | } finally { |
| 9213 | Binder.restoreCallingIdentity(identity); |
| 9214 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9215 | } |
| 9216 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9217 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9218 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9219 | * through the callback. |
| 9220 | * |
| 9221 | * @param callback The callback that will be used to send the result. |
| 9222 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9223 | * the caller is not allowlisted. |
| 9224 | */ |
| 9225 | @Override |
| 9226 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 9227 | enforceReadPermission("getCarrierRestrictionStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9228 | |
| 9229 | enforceTelephonyFeatureWithException(packageName, |
| 9230 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus"); |
| 9231 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9232 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 9233 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 9234 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9235 | throw new SecurityException("Not an authorized caller"); |
| 9236 | } |
| 9237 | final long identity = Binder.clearCallingIdentity(); |
| 9238 | try { |
| 9239 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 9240 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 9241 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9242 | } finally { |
| 9243 | Binder.restoreCallingIdentity(identity); |
| 9244 | } |
| 9245 | } |
| 9246 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9247 | @Override |
| 9248 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9249 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9250 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9251 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9252 | } |
| 9253 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9254 | @VisibleForTesting |
| 9255 | public int validateCallerAndGetCarrierId(String packageName) { |
| 9256 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9257 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 9258 | } |
| 9259 | |
| 9260 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9261 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9262 | * @param subId the subscription ID that this action applies to. |
| 9263 | * @param enabled control enable or disable radio. |
| 9264 | * {@hide} |
| 9265 | */ |
| 9266 | @Override |
| 9267 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9268 | enforceModifyPermission(); |
| 9269 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9270 | |
| 9271 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9272 | if (phone == null) { |
| 9273 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9274 | return; |
| 9275 | } |
| 9276 | try { |
| 9277 | phone.carrierActionSetRadioEnabled(enabled); |
| 9278 | } catch (Exception e) { |
| 9279 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9280 | } finally { |
| 9281 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9282 | } |
| 9283 | } |
| 9284 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9285 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9286 | * Enable or disable Voice over NR (VoNR) |
| 9287 | * @param subId the subscription ID that this action applies to. |
| 9288 | * @param enabled enable or disable VoNR. |
| 9289 | * @return operation result. |
| 9290 | */ |
| 9291 | @Override |
| 9292 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9293 | enforceModifyPermission(); |
| 9294 | final Phone phone = getPhone(subId); |
| 9295 | |
| 9296 | final long identity = Binder.clearCallingIdentity(); |
| 9297 | if (phone == null) { |
| 9298 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9299 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9300 | } |
| 9301 | |
| 9302 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9303 | try { |
| 9304 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9305 | workSource); |
| 9306 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9307 | |
| 9308 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9309 | if (DBG) { |
| 9310 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9311 | } |
| 9312 | SubscriptionManager.setSubscriptionProperty( |
| 9313 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9314 | (enabled ? "1" : "0")); |
| 9315 | } |
| 9316 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9317 | return result; |
| 9318 | } finally { |
| 9319 | Binder.restoreCallingIdentity(identity); |
| 9320 | } |
| 9321 | } |
| 9322 | |
| 9323 | /** |
| 9324 | * Is voice over NR enabled |
| 9325 | * @return true if VoNR is enabled else false |
| 9326 | */ |
| 9327 | @Override |
| 9328 | public boolean isVoNrEnabled(int subId) { |
| 9329 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9330 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9331 | final long identity = Binder.clearCallingIdentity(); |
| 9332 | try { |
| 9333 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9334 | null, subId, workSource); |
| 9335 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9336 | return isEnabled; |
| 9337 | } finally { |
| 9338 | Binder.restoreCallingIdentity(identity); |
| 9339 | } |
| 9340 | } |
| 9341 | |
| 9342 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9343 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9344 | * network status based on which carrier apps could apply actions accordingly, |
| 9345 | * enable/disable default url handler for example. |
| 9346 | * |
| 9347 | * @param subId the subscription ID that this action applies to. |
| 9348 | * @param report control start/stop reporting the default network status. |
| 9349 | * {@hide} |
| 9350 | */ |
| 9351 | @Override |
| 9352 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9353 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9354 | |
| 9355 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9356 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9357 | "carrierActionReportDefaultNetworkStatus"); |
| 9358 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9359 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9360 | |
| 9361 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9362 | if (phone == null) { |
| 9363 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9364 | return; |
| 9365 | } |
| 9366 | try { |
| 9367 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9368 | } catch (Exception e) { |
| 9369 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9372 | } |
| 9373 | } |
| 9374 | |
| 9375 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9376 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9377 | * @param subId the subscription ID that this action applies to. |
| 9378 | * {@hide} |
| 9379 | */ |
| 9380 | @Override |
| 9381 | public void carrierActionResetAll(int subId) { |
| 9382 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9383 | |
| 9384 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9385 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9386 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9387 | final Phone phone = getPhone(subId); |
| 9388 | if (phone == null) { |
| 9389 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9390 | return; |
| 9391 | } |
| 9392 | try { |
| 9393 | phone.carrierActionResetAll(); |
| 9394 | } catch (Exception e) { |
| 9395 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9396 | } |
| 9397 | } |
| 9398 | |
| 9399 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9400 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9401 | * bug report is being generated. |
| 9402 | */ |
| 9403 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9404 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9405 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9406 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9407 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9408 | + Binder.getCallingPid() |
| 9409 | + ", uid=" + Binder.getCallingUid() |
| 9410 | + "without permission " |
| 9411 | + android.Manifest.permission.DUMP); |
| 9412 | return; |
| 9413 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9414 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9415 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9416 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9417 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9418 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9419 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9420 | @NonNull String[] args) { |
| 9421 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9422 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9423 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9424 | } |
| 9425 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9426 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9427 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9428 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9429 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9430 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9431 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9432 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9433 | */ |
| 9434 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9435 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9436 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9437 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9438 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9439 | try { |
| 9440 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9441 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9442 | } catch (SecurityException se) { |
| 9443 | enforceModifyPermission(); |
| 9444 | } |
| 9445 | } else { |
| 9446 | enforceModifyPermission(); |
| 9447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9448 | |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 9449 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9450 | && null != callingPackage && opEnableMobileDataByUser()) { |
| 9451 | mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(), |
| 9452 | callingPackage, null, null); |
| 9453 | } |
| 9454 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9455 | enforceTelephonyFeatureWithException(callingPackage, |
| 9456 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9458 | final long identity = Binder.clearCallingIdentity(); |
| 9459 | try { |
| 9460 | Phone phone = getPhone(subId); |
| 9461 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9462 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9463 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 9464 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9465 | phone.getDataSettingsManager().setDataEnabled( |
| 9466 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9468 | } |
| 9469 | } finally { |
| 9470 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9471 | } |
| 9472 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9473 | |
| 9474 | /** |
| 9475 | * Get Client request stats |
| 9476 | * @return List of Client Request Stats |
| 9477 | * @hide |
| 9478 | */ |
| 9479 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9480 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9481 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9482 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9483 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9484 | return null; |
| 9485 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9486 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9487 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9488 | final long identity = Binder.clearCallingIdentity(); |
| 9489 | try { |
| 9490 | if (phone != null) { |
| 9491 | return phone.getClientRequestStats(); |
| 9492 | } |
| 9493 | |
| 9494 | return null; |
| 9495 | } finally { |
| 9496 | Binder.restoreCallingIdentity(identity); |
| 9497 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9498 | } |
| 9499 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9500 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9501 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9502 | if (uid == Process.ROOT_UID && packageName == null) { |
| 9503 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9504 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9505 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9506 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9507 | // commands that plumb through the RIL as root, like so: |
| 9508 | // $ adb root |
| 9509 | // $ adb shell cmd phone ... |
| 9510 | packageName = "root"; |
| 9511 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9512 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9513 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9514 | |
| 9515 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9516 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9517 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9518 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9519 | * @param state State of SIM (power down, power up, pass through) |
| 9520 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9521 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9522 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9523 | * |
| 9524 | **/ |
| 9525 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9526 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9527 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9528 | |
| 9529 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9530 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9531 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9532 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9533 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9534 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9535 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9536 | final long identity = Binder.clearCallingIdentity(); |
| 9537 | try { |
| 9538 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9539 | phone.setSimPowerState(state, null, workSource); |
| 9540 | } |
| 9541 | } finally { |
| 9542 | Binder.restoreCallingIdentity(identity); |
| 9543 | } |
| 9544 | } |
| 9545 | |
| 9546 | /** |
| 9547 | * Set SIM card power state. |
| 9548 | * |
| 9549 | * @param slotIndex SIM slot id. |
| 9550 | * @param state State of SIM (power down, power up, pass through) |
| 9551 | * @param callback callback to trigger after success or failure |
| 9552 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9553 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9554 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9555 | * |
| 9556 | **/ |
| 9557 | @Override |
| 9558 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9559 | IIntegerConsumer callback) { |
| 9560 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9561 | |
| 9562 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9563 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9564 | "setSimPowerStateForSlotWithCallback"); |
| 9565 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9566 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9567 | |
| 9568 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9569 | |
| 9570 | final long identity = Binder.clearCallingIdentity(); |
| 9571 | try { |
| 9572 | if (phone != null) { |
| 9573 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9574 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9575 | } |
| 9576 | } finally { |
| 9577 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9578 | } |
| 9579 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9580 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9581 | private boolean isUssdApiAllowed(int subId) { |
| 9582 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9583 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9584 | if (configManager == null) { |
| 9585 | return false; |
| 9586 | } |
| 9587 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9588 | if (pb == null) { |
| 9589 | return false; |
| 9590 | } |
| 9591 | return pb.getBoolean( |
| 9592 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9593 | } |
| 9594 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9595 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9596 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9597 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9598 | * @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] | 9599 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9600 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9601 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9602 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9603 | |
| 9604 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9605 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9607 | final long identity = Binder.clearCallingIdentity(); |
| 9608 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9609 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9610 | } finally { |
| 9611 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9612 | } |
| 9613 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9614 | |
| 9615 | /** |
| 9616 | * Get the current signal strength information for the given subscription. |
| 9617 | * Because this information is not updated when the device is in a low power state |
| 9618 | * it should not be relied-upon to be current. |
| 9619 | * @param subId Subscription index |
| 9620 | * @return the most recent cached signal strength info from the modem |
| 9621 | */ |
| 9622 | @Override |
| 9623 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9624 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9625 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9627 | final long identity = Binder.clearCallingIdentity(); |
| 9628 | try { |
| 9629 | Phone p = getPhone(subId); |
| 9630 | if (p == null) { |
| 9631 | return null; |
| 9632 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9633 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9634 | return p.getSignalStrength(); |
| 9635 | } finally { |
| 9636 | Binder.restoreCallingIdentity(identity); |
| 9637 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9638 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9639 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9640 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9641 | * Get the current modem radio state for the given slot. |
| 9642 | * @param slotIndex slot index. |
| 9643 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9644 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9645 | * @return the current radio power state from the modem |
| 9646 | */ |
| 9647 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9648 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9649 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9650 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9651 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9652 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9653 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9654 | } |
| 9655 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9656 | enforceTelephonyFeatureWithException(callingPackage, |
| 9657 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9658 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9659 | final long identity = Binder.clearCallingIdentity(); |
| 9660 | try { |
| 9661 | return phone.getRadioPowerState(); |
| 9662 | } finally { |
| 9663 | Binder.restoreCallingIdentity(identity); |
| 9664 | } |
| 9665 | } |
| 9666 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9667 | } |
| 9668 | |
| 9669 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9670 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9671 | * |
| 9672 | * <p>Requires one of the following permissions: |
| 9673 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9674 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9675 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9676 | * privileges. |
| 9677 | * |
| 9678 | * @param subId subscription id |
| 9679 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9680 | * {@code false}. |
| 9681 | */ |
| 9682 | @Override |
| 9683 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9684 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9685 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9686 | try { |
| 9687 | mApp.enforceCallingOrSelfPermission( |
| 9688 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9689 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9690 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9691 | mApp.enforceCallingOrSelfPermission( |
| 9692 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9693 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9694 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9695 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9696 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9697 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9698 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9699 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9700 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9701 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9702 | boolean isEnabled = false; |
| 9703 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9704 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9705 | Phone phone = getPhone(subId); |
| 9706 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9707 | } finally { |
| 9708 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9709 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9710 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9711 | } |
| 9712 | |
| 9713 | |
| 9714 | /** |
| 9715 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9716 | * |
| 9717 | * <p> Requires permission: |
| 9718 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9719 | * privileges. |
| 9720 | * |
| 9721 | * @param subId subscription id |
| 9722 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9723 | */ |
| 9724 | @Override |
| 9725 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9727 | mApp, subId, "setDataRoamingEnabled"); |
| 9728 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9729 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9730 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9731 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9732 | final long identity = Binder.clearCallingIdentity(); |
| 9733 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9734 | Phone phone = getPhone(subId); |
| 9735 | if (phone != null) { |
| 9736 | phone.setDataRoamingEnabled(isEnabled); |
| 9737 | } |
| 9738 | } finally { |
| 9739 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9740 | } |
| 9741 | } |
| 9742 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9743 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9744 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9745 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9746 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9747 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9748 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9749 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9750 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9751 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9752 | boolean isAllowed = true; |
| 9753 | final long identity = Binder.clearCallingIdentity(); |
| 9754 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9755 | Phone phone = getPhone(subId); |
| 9756 | if (phone != null) { |
| 9757 | isAllowed = phone.isCspPlmnEnabled(); |
| 9758 | } |
| 9759 | } finally { |
| 9760 | Binder.restoreCallingIdentity(identity); |
| 9761 | } |
| 9762 | return isAllowed; |
| 9763 | } |
| 9764 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9765 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9766 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9767 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9768 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9769 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9770 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9771 | if (phone == null) { |
| 9772 | return false; |
| 9773 | } |
| 9774 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9775 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9776 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9777 | } |
| 9778 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9779 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9780 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9781 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9782 | mApp.getSystemService(AppOpsManager.class) |
| 9783 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9784 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9785 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9786 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9787 | try { |
| 9788 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9789 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9790 | } catch (SecurityException e) { |
| 9791 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9792 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9793 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9794 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9795 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9796 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9797 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9798 | |
| 9799 | enforceTelephonyFeatureWithException(callingPackage, |
| 9800 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9801 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9802 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9803 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9804 | Binder.getCallingUid())) { |
| 9805 | isIccIdAccessRestricted = true; |
| 9806 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9807 | final long identity = Binder.clearCallingIdentity(); |
| 9808 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9809 | UiccController uiccController = UiccController.getInstance(); |
| 9810 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9811 | if (hasReadPermission) { |
| 9812 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9813 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9814 | |
| 9815 | // Remove private info if the caller doesn't have access |
| 9816 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9817 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9818 | //setting the value after compatibility check |
| 9819 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9820 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9821 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9822 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9823 | if (card == null) { |
| 9824 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9825 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9826 | continue; |
| 9827 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9828 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9829 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9830 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9831 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9832 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9833 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9834 | for (UiccPortInfo portInfo : portInfos) { |
| 9835 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9836 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9837 | if (port == null) { |
| 9838 | // assume no access if port is null |
| 9839 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9840 | continue; |
| 9841 | } |
| 9842 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9843 | uiccPortInfos.add(portInfo); |
| 9844 | } else { |
| 9845 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9846 | } |
| 9847 | } |
| 9848 | filteredInfos.add(new UiccCardInfo( |
| 9849 | cardInfo.isEuicc(), |
| 9850 | cardInfo.getCardId(), |
| 9851 | null, |
| 9852 | cardInfo.getPhysicalSlotIndex(), |
| 9853 | cardInfo.isRemovable(), |
| 9854 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9855 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9856 | } |
| 9857 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9858 | } finally { |
| 9859 | Binder.restoreCallingIdentity(identity); |
| 9860 | } |
| 9861 | } |
| 9862 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9863 | /** |
| 9864 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9865 | * generally private and require carrier privileges to view. |
| 9866 | * |
| 9867 | * @hide |
| 9868 | */ |
| 9869 | @NonNull |
| 9870 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9871 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9872 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9873 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9874 | } |
| 9875 | return new UiccCardInfo( |
| 9876 | cardInfo.isEuicc(), |
| 9877 | cardInfo.getCardId(), |
| 9878 | null, |
| 9879 | cardInfo.getPhysicalSlotIndex(), |
| 9880 | cardInfo.isRemovable(), |
| 9881 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9882 | portinfo |
| 9883 | ); |
| 9884 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9885 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9886 | /** |
| 9887 | * @hide |
| 9888 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9889 | * These values are generally private and require carrier privileges to view. |
| 9890 | */ |
| 9891 | @NonNull |
| 9892 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9893 | return new UiccPortInfo( |
| 9894 | UiccPortInfo.ICCID_REDACTED, |
| 9895 | portInfo.getPortIndex(), |
| 9896 | portInfo.getLogicalSlotIndex(), |
| 9897 | portInfo.isActive() |
| 9898 | ); |
| 9899 | } |
| 9900 | @Override |
| 9901 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9902 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9903 | mApp.getSystemService(AppOpsManager.class) |
| 9904 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9905 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9906 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9907 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9908 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9909 | // we are reading iccId which is PII data. |
| 9910 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9911 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9912 | enforceTelephonyFeatureWithException(callingPackage, |
| 9913 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 9914 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9915 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9916 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9917 | Binder.getCallingUid())) { |
| 9918 | isLogicalSlotAccessRestricted = true; |
| 9919 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9920 | final long identity = Binder.clearCallingIdentity(); |
| 9921 | try { |
| 9922 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9923 | if (slots == null || slots.length == 0) { |
| 9924 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9925 | return null; |
| 9926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9927 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9928 | for (int i = 0; i < slots.length; i++) { |
| 9929 | UiccSlot slot = slots[i]; |
| 9930 | if (slot == null) { |
| 9931 | continue; |
| 9932 | } |
| 9933 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9934 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9935 | UiccCard card = slot.getUiccCard(); |
| 9936 | if (card != null) { |
| 9937 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9938 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9939 | cardId = slot.getEid(); |
| 9940 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9941 | // If cardId is null, use iccId of default port as cardId. |
| 9942 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9943 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9944 | } |
| 9945 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9946 | if (cardId != null) { |
| 9947 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9948 | // if cardId is an EID, it's all digits so this is fine |
| 9949 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9950 | } |
| 9951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9952 | int cardState = 0; |
| 9953 | switch (slot.getCardState()) { |
| 9954 | case CARDSTATE_ABSENT: |
| 9955 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9956 | break; |
| 9957 | case CARDSTATE_PRESENT: |
| 9958 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9959 | break; |
| 9960 | case CARDSTATE_ERROR: |
| 9961 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9962 | break; |
| 9963 | case CARDSTATE_RESTRICTED: |
| 9964 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9965 | break; |
| 9966 | default: |
| 9967 | break; |
| 9968 | |
| 9969 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9970 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9971 | int[] portIndexes = slot.getPortList(); |
| 9972 | for (int portIdx : portIndexes) { |
| 9973 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9974 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9975 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9976 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9977 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9978 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9979 | slot.isEuicc(), |
| 9980 | cardId, |
| 9981 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9982 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9983 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9984 | //setting the value after compatibility check |
| 9985 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9986 | } |
| 9987 | return infos; |
| 9988 | } finally { |
| 9989 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9990 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9991 | } |
| 9992 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9993 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9994 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9995 | boolean hasReadPermission) { |
| 9996 | String iccId = slot.getIccId(portIndex); |
| 9997 | if (hasReadPermission) { // if has read permission |
| 9998 | return iccId; |
| 9999 | } else { |
| 10000 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10001 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10002 | // if no read permission, checking carrier privilege access |
| 10003 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10004 | return iccId; |
| 10005 | } |
| 10006 | } |
| 10007 | } |
| 10008 | // No read permission or carrier privilege access. |
| 10009 | return UiccPortInfo.ICCID_REDACTED; |
| 10010 | } |
| 10011 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10012 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10013 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10014 | public boolean switchSlots(int[] physicalSlots) { |
| 10015 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10016 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10017 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10018 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10020 | final long identity = Binder.clearCallingIdentity(); |
| 10021 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10022 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10023 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10024 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10025 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10026 | physicalSlots[i], i)); |
| 10027 | } |
| 10028 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10029 | } finally { |
| 10030 | Binder.restoreCallingIdentity(identity); |
| 10031 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10032 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10033 | |
| 10034 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10035 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10036 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10037 | enforceModifyPermission(); |
| 10038 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10039 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10040 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10041 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10042 | final long identity = Binder.clearCallingIdentity(); |
| 10043 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10044 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10045 | } finally { |
| 10046 | Binder.restoreCallingIdentity(identity); |
| 10047 | } |
| 10048 | } |
| 10049 | |
| 10050 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10051 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10052 | enforceTelephonyFeatureWithException(callingPackage, |
| 10053 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10054 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10055 | final long identity = Binder.clearCallingIdentity(); |
| 10056 | try { |
| 10057 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10058 | } finally { |
| 10059 | Binder.restoreCallingIdentity(identity); |
| 10060 | } |
| 10061 | } |
| 10062 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10063 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10064 | * A test API to reload the UICC profile. |
| 10065 | * |
| 10066 | * <p>Requires that the calling app has permission |
| 10067 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10068 | * @hide |
| 10069 | */ |
| 10070 | @Override |
| 10071 | public void refreshUiccProfile(int subId) { |
| 10072 | enforceModifyPermission(); |
| 10073 | |
| 10074 | final long identity = Binder.clearCallingIdentity(); |
| 10075 | try { |
| 10076 | Phone phone = getPhone(subId); |
| 10077 | if (phone == null) { |
| 10078 | return; |
| 10079 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10080 | UiccPort uiccPort = phone.getUiccPort(); |
| 10081 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10082 | return; |
| 10083 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10084 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10085 | if (uiccProfile == null) { |
| 10086 | return; |
| 10087 | } |
| 10088 | uiccProfile.refresh(); |
| 10089 | } finally { |
| 10090 | Binder.restoreCallingIdentity(identity); |
| 10091 | } |
| 10092 | } |
| 10093 | |
| 10094 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10095 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10096 | */ |
| 10097 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10098 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10099 | } |
| 10100 | |
| 10101 | /** |
| 10102 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 10103 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 10104 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 10105 | */ |
| 10106 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 10107 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10108 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 10109 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10110 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 10111 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 10112 | return isDataRoamingEnabled; |
| 10113 | } |
| 10114 | |
| 10115 | /** |
| 10116 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10117 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10118 | */ |
| 10119 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10120 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10121 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10122 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10123 | return list.get(phoneId); |
| 10124 | } |
| 10125 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10126 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10127 | |
| 10128 | @Override |
| 10129 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10130 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10131 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10132 | |
| 10133 | final long identity = Binder.clearCallingIdentity(); |
| 10134 | try { |
| 10135 | final Phone phone = getPhone(subId); |
| 10136 | if (phone == null) { |
| 10137 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10138 | return; |
| 10139 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10140 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10141 | if (cpt != null) { |
| 10142 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10143 | } |
| 10144 | // 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] | 10145 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10146 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10147 | if (carrierPrivilegeRules == null) { |
| 10148 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10149 | } else { |
| 10150 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10151 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10152 | } finally { |
| 10153 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10154 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10155 | } |
| 10156 | |
| 10157 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10158 | public void setCarrierServicePackageOverride( |
| 10159 | int subId, String carrierServicePackage, String callingPackage) { |
| 10160 | TelephonyPermissions.enforceShellOnly( |
| 10161 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10162 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10163 | final long identity = Binder.clearCallingIdentity(); |
| 10164 | try { |
| 10165 | final Phone phone = getPhone(subId); |
| 10166 | if (phone == null || phone.getSubId() != subId) { |
| 10167 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10168 | throw new IllegalArgumentException("No phone for subid"); |
| 10169 | } |
| 10170 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10171 | if (cpt == null) { |
| 10172 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10173 | throw new IllegalStateException("No CPT for phone"); |
| 10174 | } |
| 10175 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10176 | } finally { |
| 10177 | Binder.restoreCallingIdentity(identity); |
| 10178 | } |
| 10179 | } |
| 10180 | |
| 10181 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10182 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10183 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10184 | |
| 10185 | final long identity = Binder.clearCallingIdentity(); |
| 10186 | try { |
| 10187 | final Phone phone = getPhone(subId); |
| 10188 | if (phone == null) { |
| 10189 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10190 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10191 | } |
| 10192 | return phone.getCarrierIdListVersion(); |
| 10193 | } finally { |
| 10194 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10195 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10196 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10197 | |
| 10198 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10199 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10200 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10201 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10202 | mApp, subId, callingPackage, callingFeatureId, |
| 10203 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10204 | return -1; |
| 10205 | } |
| 10206 | |
| 10207 | final long identity = Binder.clearCallingIdentity(); |
| 10208 | try { |
| 10209 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10210 | } finally { |
| 10211 | Binder.restoreCallingIdentity(identity); |
| 10212 | } |
| 10213 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10214 | |
| 10215 | @Override |
| 10216 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10217 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10218 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10219 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10220 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10221 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10222 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10223 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10224 | final long identity = Binder.clearCallingIdentity(); |
| 10225 | try { |
| 10226 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10227 | } finally { |
| 10228 | Binder.restoreCallingIdentity(identity); |
| 10229 | } |
| 10230 | } |
| 10231 | |
| 10232 | @Override |
| 10233 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10235 | mApp, subId, "setCdmaRoamingMode"); |
| 10236 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10237 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10238 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10239 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10240 | final long identity = Binder.clearCallingIdentity(); |
| 10241 | try { |
| 10242 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10243 | } finally { |
| 10244 | Binder.restoreCallingIdentity(identity); |
| 10245 | } |
| 10246 | } |
| 10247 | |
| 10248 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10249 | public int getCdmaSubscriptionMode(int subId) { |
| 10250 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10251 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10252 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10253 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10254 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10255 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10256 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10257 | final long identity = Binder.clearCallingIdentity(); |
| 10258 | try { |
| 10259 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10260 | } finally { |
| 10261 | Binder.restoreCallingIdentity(identity); |
| 10262 | } |
| 10263 | } |
| 10264 | |
| 10265 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10266 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10268 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10269 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10270 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10271 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10272 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10273 | final long identity = Binder.clearCallingIdentity(); |
| 10274 | try { |
| 10275 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10276 | } finally { |
| 10277 | Binder.restoreCallingIdentity(identity); |
| 10278 | } |
| 10279 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10280 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10281 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10282 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10283 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10284 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10285 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10286 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10287 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10288 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10289 | |
| 10290 | enforceTelephonyFeatureWithException(callingPackage, |
| 10291 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10292 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10293 | final long identity = Binder.clearCallingIdentity(); |
| 10294 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10295 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10296 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10297 | if (phone.getEmergencyNumberTracker() != null |
| 10298 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10299 | emergencyNumberListInternal.put( |
| 10300 | phone.getSubId(), |
| 10301 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10302 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10303 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10304 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10305 | } finally { |
| 10306 | Binder.restoreCallingIdentity(identity); |
| 10307 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10308 | } |
| 10309 | |
| 10310 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10311 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10312 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10313 | if (!exactMatch) { |
| 10314 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10315 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10316 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10317 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10318 | |
| 10319 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10320 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10321 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10322 | final long identity = Binder.clearCallingIdentity(); |
| 10323 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10324 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10325 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10326 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10327 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10328 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10329 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10330 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10331 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10332 | } |
| 10333 | return false; |
| 10334 | } finally { |
| 10335 | Binder.restoreCallingIdentity(identity); |
| 10336 | } |
| 10337 | } |
| 10338 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10339 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10340 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10341 | */ |
| 10342 | @Override |
| 10343 | public void startEmergencyCallbackMode() { |
| 10344 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10345 | "startEmergencyCallbackMode"); |
| 10346 | enforceModifyPermission(); |
| 10347 | final long identity = Binder.clearCallingIdentity(); |
| 10348 | try { |
| 10349 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10350 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10351 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10352 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10353 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10354 | gsmCdmaPhone.obtainMessage( |
| 10355 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10356 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10357 | } |
| 10358 | } |
| 10359 | } finally { |
| 10360 | Binder.restoreCallingIdentity(identity); |
| 10361 | } |
| 10362 | } |
| 10363 | |
| 10364 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10365 | * Update emergency number list for test mode. |
| 10366 | */ |
| 10367 | @Override |
| 10368 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10369 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10370 | "updateEmergencyNumberListTestMode"); |
| 10371 | |
| 10372 | final long identity = Binder.clearCallingIdentity(); |
| 10373 | try { |
| 10374 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10375 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10376 | if (tracker != null) { |
| 10377 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10378 | } |
| 10379 | } |
| 10380 | } finally { |
| 10381 | Binder.restoreCallingIdentity(identity); |
| 10382 | } |
| 10383 | } |
| 10384 | |
| 10385 | /** |
| 10386 | * Get the full emergency number list for test mode. |
| 10387 | */ |
| 10388 | @Override |
| 10389 | public List<String> getEmergencyNumberListTestMode() { |
| 10390 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10391 | "getEmergencyNumberListTestMode"); |
| 10392 | |
| 10393 | final long identity = Binder.clearCallingIdentity(); |
| 10394 | try { |
| 10395 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10396 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10397 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10398 | if (tracker != null) { |
| 10399 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10400 | emergencyNumbers.add(num.getNumber()); |
| 10401 | } |
| 10402 | } |
| 10403 | } |
| 10404 | return new ArrayList<>(emergencyNumbers); |
| 10405 | } finally { |
| 10406 | Binder.restoreCallingIdentity(identity); |
| 10407 | } |
| 10408 | } |
| 10409 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10410 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10411 | public int getEmergencyNumberDbVersion(int subId) { |
| 10412 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10413 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10414 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10415 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10416 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10417 | final long identity = Binder.clearCallingIdentity(); |
| 10418 | try { |
| 10419 | final Phone phone = getPhone(subId); |
| 10420 | if (phone == null) { |
| 10421 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10422 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10423 | } |
| 10424 | return phone.getEmergencyNumberDbVersion(); |
| 10425 | } finally { |
| 10426 | Binder.restoreCallingIdentity(identity); |
| 10427 | } |
| 10428 | } |
| 10429 | |
| 10430 | @Override |
| 10431 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10432 | enforceModifyPermission(); |
| 10433 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10434 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10435 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10436 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10437 | final long identity = Binder.clearCallingIdentity(); |
| 10438 | try { |
| 10439 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10440 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10441 | if (tracker != null) { |
| 10442 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10443 | } |
| 10444 | } |
| 10445 | } finally { |
| 10446 | Binder.restoreCallingIdentity(identity); |
| 10447 | } |
| 10448 | } |
| 10449 | |
| 10450 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10451 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10452 | enforceActiveEmergencySessionPermission(); |
| 10453 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10454 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10455 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10456 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10457 | final long identity = Binder.clearCallingIdentity(); |
| 10458 | try { |
| 10459 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10460 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10461 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10462 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10463 | } |
| 10464 | } |
| 10465 | } finally { |
| 10466 | Binder.restoreCallingIdentity(identity); |
| 10467 | } |
| 10468 | } |
| 10469 | |
| 10470 | @Override |
| 10471 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10472 | enforceActiveEmergencySessionPermission(); |
| 10473 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10474 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10475 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10476 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10477 | final long identity = Binder.clearCallingIdentity(); |
| 10478 | try { |
| 10479 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10480 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10481 | if (tracker != null) { |
| 10482 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10483 | } |
| 10484 | } |
| 10485 | } finally { |
| 10486 | Binder.restoreCallingIdentity(identity); |
| 10487 | } |
| 10488 | } |
| 10489 | |
| 10490 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10491 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10492 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10493 | Phone phone = getPhone(subId); |
| 10494 | if (phone == null) { |
| 10495 | return null; |
| 10496 | } |
| 10497 | final long identity = Binder.clearCallingIdentity(); |
| 10498 | try { |
| 10499 | UiccProfile profile = UiccController.getInstance() |
| 10500 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10501 | if (profile != null) { |
| 10502 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10503 | } |
| 10504 | } finally { |
| 10505 | Binder.restoreCallingIdentity(identity); |
| 10506 | } |
| 10507 | return null; |
| 10508 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10509 | |
| 10510 | /** |
| 10511 | * Enable or disable a modem stack. |
| 10512 | */ |
| 10513 | @Override |
| 10514 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10515 | enforceModifyPermission(); |
| 10516 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10517 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10518 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10519 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10520 | final long identity = Binder.clearCallingIdentity(); |
| 10521 | try { |
| 10522 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10523 | if (phone == null) { |
| 10524 | return false; |
| 10525 | } else { |
| 10526 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10527 | } |
| 10528 | } finally { |
| 10529 | Binder.restoreCallingIdentity(identity); |
| 10530 | } |
| 10531 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10532 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10533 | /** |
| 10534 | * Whether a modem stack is enabled or not. |
| 10535 | */ |
| 10536 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10537 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10538 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10539 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10540 | if (phone == null) return false; |
| 10541 | |
| 10542 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10543 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10544 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10545 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10546 | } |
| 10547 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10548 | enforceTelephonyFeatureWithException(callingPackage, |
| 10549 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10550 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10551 | final long identity = Binder.clearCallingIdentity(); |
| 10552 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10553 | try { |
| 10554 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10555 | } catch (NoSuchElementException ex) { |
| 10556 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10557 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10558 | } finally { |
| 10559 | Binder.restoreCallingIdentity(identity); |
| 10560 | } |
| 10561 | } |
| 10562 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10563 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10564 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10565 | enforceModifyPermission(); |
| 10566 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10567 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10568 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10569 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10570 | final long identity = Binder.clearCallingIdentity(); |
| 10571 | try { |
| 10572 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10573 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10574 | .commit(); |
| 10575 | } finally { |
| 10576 | Binder.restoreCallingIdentity(identity); |
| 10577 | } |
| 10578 | } |
| 10579 | |
| 10580 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10581 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10582 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10584 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10585 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10586 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10587 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10588 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10589 | enforceTelephonyFeatureWithException(callingPackage, |
| 10590 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10591 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10592 | final long identity = Binder.clearCallingIdentity(); |
| 10593 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10594 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10595 | } finally { |
| 10596 | Binder.restoreCallingIdentity(identity); |
| 10597 | } |
| 10598 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10599 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10600 | @TelephonyManager.IsMultiSimSupportedResult |
| 10601 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10602 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10603 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10604 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10605 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10606 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10607 | } |
| 10608 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10609 | // supported by the modem, indicate that it is restricted. |
| 10610 | PhoneCapability staticCapability = |
| 10611 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10612 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10613 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10614 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10615 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10616 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10617 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10618 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10619 | } |
| 10620 | // Check if support of multiple SIMs is restricted by carrier |
| 10621 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10622 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10623 | } |
| 10624 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10625 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10626 | } |
| 10627 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10628 | /** |
| 10629 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10630 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10631 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10632 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10633 | * @param numOfSims number of active sims we want to switch to |
| 10634 | */ |
| 10635 | @Override |
| 10636 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10637 | if (numOfSims == 1) { |
| 10638 | enforceModifyPermission(); |
| 10639 | } else { |
| 10640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10641 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10642 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10643 | |
| 10644 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10645 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10646 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10647 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10648 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10649 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10650 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10651 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10652 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10653 | return; |
| 10654 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10655 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10656 | } finally { |
| 10657 | Binder.restoreCallingIdentity(identity); |
| 10658 | } |
| 10659 | } |
| 10660 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10661 | @Override |
| 10662 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10663 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10664 | |
| 10665 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10666 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10667 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10668 | Phone phone = getPhone(subId); |
| 10669 | if (phone == null) { |
| 10670 | return false; |
| 10671 | } |
| 10672 | final long identity = Binder.clearCallingIdentity(); |
| 10673 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10674 | UiccPort uiccPort = phone.getUiccPort(); |
| 10675 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10676 | return false; |
| 10677 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10678 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10679 | if (uiccProfile == null) { |
| 10680 | return false; |
| 10681 | } |
| 10682 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10683 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10684 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10685 | } |
| 10686 | return false; |
| 10687 | } finally { |
| 10688 | Binder.restoreCallingIdentity(identity); |
| 10689 | } |
| 10690 | } |
| 10691 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10692 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10693 | * Get whether making changes to modem configurations will trigger reboot. |
| 10694 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10695 | */ |
| 10696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10697 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10698 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10699 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10700 | mApp, subId, callingPackage, callingFeatureId, |
| 10701 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10702 | return false; |
| 10703 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10704 | |
| 10705 | enforceTelephonyFeatureWithException(callingPackage, |
| 10706 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10707 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10708 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10709 | final long identity = Binder.clearCallingIdentity(); |
| 10710 | try { |
| 10711 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10712 | } finally { |
| 10713 | Binder.restoreCallingIdentity(identity); |
| 10714 | } |
| 10715 | } |
| 10716 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10717 | private void updateModemStateMetrics() { |
| 10718 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10719 | // TODO: check the state for each modem if the api is ready. |
| 10720 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10721 | } |
| 10722 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10723 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10724 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10725 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10726 | // Verify that the callingPackage belongs to the calling UID |
| 10727 | mApp.getSystemService(AppOpsManager.class) |
| 10728 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10729 | |
| 10730 | enforceTelephonyFeatureWithException(callingPackage, |
| 10731 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10732 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10733 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10734 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10735 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10736 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10737 | if (slotInfos != null) { |
| 10738 | for (int i = 0; i < slotInfos.length; i++) { |
| 10739 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10740 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10741 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10742 | portInfo.getLogicalSlotIndex())); |
| 10743 | } |
| 10744 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10745 | } |
| 10746 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10747 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10748 | } finally { |
| 10749 | Binder.restoreCallingIdentity(identity); |
| 10750 | } |
| 10751 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10752 | |
| 10753 | /** |
| 10754 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10755 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10756 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10757 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10758 | @Override |
| 10759 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10760 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10761 | } |
| 10762 | |
| 10763 | /** |
| 10764 | * Get the HAL Version of a specific service |
| 10765 | */ |
| 10766 | @Override |
| 10767 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10768 | Phone phone = getDefaultPhone(); |
| 10769 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10770 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10771 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10772 | return hv.major * 100 + hv.minor; |
| 10773 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10774 | |
| 10775 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10776 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10777 | * |
| 10778 | * @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] | 10779 | */ |
| 10780 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10781 | public @Nullable String getCurrentPackageName() { |
| 10782 | PackageManager pm = mApp.getPackageManager(); |
| 10783 | String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid()); |
| 10784 | return packageNames == null ? null : packageNames[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10785 | } |
| 10786 | |
| 10787 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10788 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10789 | * corresponding network requests on a subId. |
| 10790 | * |
| 10791 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10792 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10793 | * 2) APN is un-metered for this subscription, or |
| 10794 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10795 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10796 | * |
| 10797 | * @return whether data is allowed for a apn type. |
| 10798 | * |
| 10799 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10800 | */ |
| 10801 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10802 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10803 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10804 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10805 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10806 | enforceTelephonyFeatureWithException(callingPackage, |
| 10807 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10808 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10809 | // Now that all security checks passes, perform the operation as ourselves. |
| 10810 | final long identity = Binder.clearCallingIdentity(); |
| 10811 | try { |
| 10812 | Phone phone = getPhone(subId); |
| 10813 | if (phone == null) return false; |
| 10814 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10815 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10816 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10817 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10818 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10819 | phone.getServiceState().getDataRoaming()); |
| 10820 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10821 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10822 | } finally { |
| 10823 | Binder.restoreCallingIdentity(identity); |
| 10824 | } |
| 10825 | } |
| 10826 | |
| 10827 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10828 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10829 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10830 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10831 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10832 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10833 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10834 | // Now that all security checks passes, perform the operation as ourselves. |
| 10835 | final long identity = Binder.clearCallingIdentity(); |
| 10836 | try { |
| 10837 | Phone phone = getPhone(subId); |
| 10838 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10839 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10840 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10841 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10842 | } finally { |
| 10843 | Binder.restoreCallingIdentity(identity); |
| 10844 | } |
| 10845 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10846 | |
| 10847 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10848 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10849 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10850 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10851 | |
| 10852 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10853 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10854 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10855 | long token = Binder.clearCallingIdentity(); |
| 10856 | try { |
| 10857 | Phone phone = getPhone(subscriptionId); |
| 10858 | if (phone == null) { |
| 10859 | try { |
| 10860 | if (resultCallback != null) { |
| 10861 | resultCallback.accept(false); |
| 10862 | } |
| 10863 | } catch (RemoteException e) { |
| 10864 | // ignore |
| 10865 | } |
| 10866 | return; |
| 10867 | } |
| 10868 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10869 | Pair.create(specifiers, (x) -> { |
| 10870 | try { |
| 10871 | if (resultCallback != null) { |
| 10872 | resultCallback.accept(x); |
| 10873 | } |
| 10874 | } catch (RemoteException e) { |
| 10875 | // ignore |
| 10876 | } |
| 10877 | }); |
| 10878 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10879 | } finally { |
| 10880 | Binder.restoreCallingIdentity(token); |
| 10881 | } |
| 10882 | } |
| 10883 | |
| 10884 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10885 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10886 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10887 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10888 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10889 | |
| 10890 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10891 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 10892 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10893 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10894 | final long identity = Binder.clearCallingIdentity(); |
| 10895 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10896 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10897 | if (result instanceof IllegalStateException) { |
| 10898 | throw (IllegalStateException) result; |
| 10899 | } |
| 10900 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10901 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10902 | return specifiers; |
| 10903 | } finally { |
| 10904 | Binder.restoreCallingIdentity(identity); |
| 10905 | } |
| 10906 | } |
| 10907 | |
| 10908 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10909 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10910 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10911 | |
| 10912 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10913 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 10914 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10915 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10916 | } |
| 10917 | |
| 10918 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10919 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10920 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10921 | if (callingPackage == null) { |
| 10922 | callingPackage = getCurrentPackageName(); |
| 10923 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10924 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10925 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10926 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10927 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10928 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10929 | } |
| 10930 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10931 | Intent intent = new Intent(); |
| 10932 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10933 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10934 | // Bring up choose default SMS subscription dialog right now |
| 10935 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10936 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10937 | mApp.startActivity(intent); |
| 10938 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10939 | |
| 10940 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10941 | public void showSwitchToManagedProfileDialog() { |
| 10942 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 10943 | try { |
| 10944 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 10945 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 10946 | // for work telephony. |
| 10947 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 10948 | intent.setData(Uri.parse("smsto:")); |
| 10949 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10950 | mApp.startActivity(intent); |
| 10951 | } catch (ActivityNotFoundException e) { |
| 10952 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 10953 | Intent intent = new Intent(); |
| 10954 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10955 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10956 | mApp.startActivity(intent); |
| 10957 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10958 | } |
| 10959 | |
| 10960 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10961 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10962 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10963 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 10964 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10965 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10966 | final long identity = Binder.clearCallingIdentity(); |
| 10967 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10968 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10969 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10970 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10971 | return carrierUAProfUrl; |
| 10972 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10973 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10974 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10975 | } finally { |
| 10976 | Binder.restoreCallingIdentity(identity); |
| 10977 | } |
| 10978 | } |
| 10979 | |
| 10980 | @Override |
| 10981 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10982 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10983 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 10984 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10985 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10986 | final long identity = Binder.clearCallingIdentity(); |
| 10987 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10988 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10989 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10990 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10991 | return carrierUserAgent; |
| 10992 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10993 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10994 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10995 | } finally { |
| 10996 | Binder.restoreCallingIdentity(identity); |
| 10997 | } |
| 10998 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10999 | |
| 11000 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11001 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11002 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11003 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11004 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11005 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11006 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11007 | final long identity = Binder.clearCallingIdentity(); |
| 11008 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11009 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11010 | if (phone == null) return false; |
| 11011 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11012 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11013 | } finally { |
| 11014 | Binder.restoreCallingIdentity(identity); |
| 11015 | } |
| 11016 | } |
| 11017 | |
| 11018 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11019 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11020 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11021 | enforceModifyPermission(); |
| 11022 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11023 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11024 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11025 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11026 | final long identity = Binder.clearCallingIdentity(); |
| 11027 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11028 | Phone phone = getPhone(subscriptionId); |
| 11029 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11030 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11031 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11032 | } finally { |
| 11033 | Binder.restoreCallingIdentity(identity); |
| 11034 | } |
| 11035 | } |
| 11036 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11037 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11038 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11039 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11040 | * otherwise. |
| 11041 | */ |
| 11042 | @Override |
| 11043 | public void setCepEnabled(boolean isCepEnabled) { |
| 11044 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11045 | |
| 11046 | final long identity = Binder.clearCallingIdentity(); |
| 11047 | try { |
| 11048 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11049 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11050 | Phone defaultPhone = phone.getImsPhone(); |
| 11051 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11052 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11053 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11054 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11055 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11056 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11057 | + imsPhone.getMsisdn()); |
| 11058 | } |
| 11059 | } |
| 11060 | } finally { |
| 11061 | Binder.restoreCallingIdentity(identity); |
| 11062 | } |
| 11063 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11064 | |
| 11065 | /** |
| 11066 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11067 | * |
| 11068 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11069 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11070 | * before being read. |
| 11071 | */ |
| 11072 | @Override |
| 11073 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11074 | isCompressed) { |
| 11075 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11076 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11077 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11078 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11079 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11080 | |
| 11081 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11082 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11083 | Binder.getCallingUserHandle())) { |
| 11084 | if (!isImsAvailableOnDevice()) { |
| 11085 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11086 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11087 | throw new IllegalStateException("IMS not available on device."); |
| 11088 | } |
| 11089 | } else { |
| 11090 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11091 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11092 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11093 | } |
| 11094 | |
| 11095 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11096 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11097 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11098 | } finally { |
| 11099 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11100 | } |
| 11101 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11102 | |
| 11103 | @Override |
| 11104 | public boolean isIccLockEnabled(int subId) { |
| 11105 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11106 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11107 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11108 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11109 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11110 | // Now that all security checks passes, perform the operation as ourselves. |
| 11111 | final long identity = Binder.clearCallingIdentity(); |
| 11112 | try { |
| 11113 | Phone phone = getPhone(subId); |
| 11114 | if (phone != null && phone.getIccCard() != null) { |
| 11115 | return phone.getIccCard().getIccLockEnabled(); |
| 11116 | } else { |
| 11117 | return false; |
| 11118 | } |
| 11119 | } finally { |
| 11120 | Binder.restoreCallingIdentity(identity); |
| 11121 | } |
| 11122 | } |
| 11123 | |
| 11124 | /** |
| 11125 | * Set the ICC pin lock enabled or disabled. |
| 11126 | * |
| 11127 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11128 | * three cases: |
| 11129 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11130 | * successfully. |
| 11131 | * - Positive number and zero for remaining password attempts. |
| 11132 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11133 | * |
| 11134 | */ |
| 11135 | @Override |
| 11136 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11137 | enforceModifyPermission(); |
| 11138 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11139 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11140 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11141 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11142 | Phone phone = getPhone(subId); |
| 11143 | if (phone == null) { |
| 11144 | return 0; |
| 11145 | } |
| 11146 | // Now that all security checks passes, perform the operation as ourselves. |
| 11147 | final long identity = Binder.clearCallingIdentity(); |
| 11148 | try { |
| 11149 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11150 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11151 | return attemptsRemaining; |
| 11152 | |
| 11153 | } catch (Exception e) { |
| 11154 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11155 | } finally { |
| 11156 | Binder.restoreCallingIdentity(identity); |
| 11157 | } |
| 11158 | return 0; |
| 11159 | } |
| 11160 | |
| 11161 | /** |
| 11162 | * Change the ICC password used in ICC pin lock. |
| 11163 | * |
| 11164 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11165 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11166 | * - Positive number and zero for remaining password attempts. |
| 11167 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11168 | * |
| 11169 | */ |
| 11170 | @Override |
| 11171 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11172 | enforceModifyPermission(); |
| 11173 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11174 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11175 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11176 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11177 | Phone phone = getPhone(subId); |
| 11178 | if (phone == null) { |
| 11179 | return 0; |
| 11180 | } |
| 11181 | // Now that all security checks passes, perform the operation as ourselves. |
| 11182 | final long identity = Binder.clearCallingIdentity(); |
| 11183 | try { |
| 11184 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11185 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11186 | return attemptsRemaining; |
| 11187 | |
| 11188 | } catch (Exception e) { |
| 11189 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11190 | } finally { |
| 11191 | Binder.restoreCallingIdentity(identity); |
| 11192 | } |
| 11193 | return 0; |
| 11194 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11195 | |
| 11196 | /** |
| 11197 | * Request for receiving user activity notification |
| 11198 | */ |
| 11199 | @Override |
| 11200 | public void requestUserActivityNotification() { |
| 11201 | if (!mNotifyUserActivity.get() |
| 11202 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11203 | mNotifyUserActivity.set(true); |
| 11204 | } |
| 11205 | } |
| 11206 | |
| 11207 | /** |
| 11208 | * Called when userActivity is signalled in the power manager. |
| 11209 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11210 | */ |
| 11211 | @Override |
| 11212 | public void userActivity() { |
| 11213 | // *************************************** |
| 11214 | // * Inherited from PhoneWindowManager * |
| 11215 | // *************************************** |
| 11216 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11217 | // WITH ITS LOCKS HELD. |
| 11218 | // |
| 11219 | // This code must be VERY careful about the locks |
| 11220 | // it acquires. |
| 11221 | // In fact, the current code acquires way too many, |
| 11222 | // and probably has lurking deadlocks. |
| 11223 | |
| 11224 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 11225 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11226 | } |
| 11227 | |
| 11228 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11229 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11230 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11231 | } |
| 11232 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11233 | |
| 11234 | @Override |
| 11235 | public boolean canConnectTo5GInDsdsMode() { |
| 11236 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11237 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11238 | |
| 11239 | @Override |
| 11240 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11241 | String callingFeatureId) { |
| 11242 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11243 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11244 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11245 | } |
| 11246 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11247 | enforceTelephonyFeatureWithException(callingPackage, |
| 11248 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11249 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11250 | Phone phone = getPhone(subId); |
| 11251 | if (phone == null) { |
| 11252 | throw new RuntimeException("phone is not available"); |
| 11253 | } |
| 11254 | // Now that all security checks passes, perform the operation as ourselves. |
| 11255 | final long identity = Binder.clearCallingIdentity(); |
| 11256 | try { |
| 11257 | return phone.getEquivalentHomePlmns(); |
| 11258 | } finally { |
| 11259 | Binder.restoreCallingIdentity(identity); |
| 11260 | } |
| 11261 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11262 | |
| 11263 | @Override |
| 11264 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11265 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11266 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11267 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11268 | "isRadioInterfaceCapabilitySupported"); |
| 11269 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11270 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11271 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11272 | if (radioInterfaceCapabilities == null) { |
| 11273 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11274 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11275 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11276 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11277 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11278 | @Override |
| 11279 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11280 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11281 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11282 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11283 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11284 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11285 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11286 | |
| 11287 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11288 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11289 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11290 | if (DBG) { |
| 11291 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11292 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11293 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11294 | } |
| 11295 | |
| 11296 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11297 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11298 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11299 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11300 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11301 | if (callback != null) { |
| 11302 | try { |
| 11303 | callback.onAuthenticationFailure( |
| 11304 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11305 | } catch (RemoteException exception) { |
| 11306 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11307 | } |
| 11308 | return; |
| 11309 | } |
| 11310 | } |
| 11311 | |
| 11312 | final long token = Binder.clearCallingIdentity(); |
| 11313 | try { |
| 11314 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11315 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11316 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11317 | } finally { |
| 11318 | Binder.restoreCallingIdentity(token); |
| 11319 | } |
| 11320 | } |
| 11321 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11322 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11323 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11324 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11325 | * requested radio power state will actually be set. See {@link |
| 11326 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11327 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11328 | * @param enable {@code true} if trying to turn radio on. |
| 11329 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11330 | * false}. |
| 11331 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11332 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11333 | boolean isPhoneAvailable = false; |
| 11334 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11335 | Phone phone = PhoneFactory.getPhone(i); |
| 11336 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11337 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11338 | isPhoneAvailable = true; |
| 11339 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11340 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11341 | |
| 11342 | // return true if successfully informed the phone object about the thermal radio power |
| 11343 | // request. |
| 11344 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11345 | } |
| 11346 | |
| 11347 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11348 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11349 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11350 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11351 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11352 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11353 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11354 | } |
| 11355 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11356 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11357 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11358 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11359 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11360 | } |
| 11361 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11362 | setDataEnabledForReason( |
| 11363 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11364 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11365 | if (isDataThrottlingSupported) { |
| 11366 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11367 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11368 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11369 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11370 | } else if (thermalMitigationResult |
| 11371 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11372 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11373 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11374 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11375 | } |
| 11376 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11377 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11378 | |
| 11379 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11380 | } |
| 11381 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11382 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11383 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11384 | for (String pckg : context.getResources() |
| 11385 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11386 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11387 | } |
| 11388 | } |
| 11389 | |
| 11390 | return sThermalMitigationAllowlistedPackages; |
| 11391 | } |
| 11392 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11393 | private boolean isAnyPhoneInEmergencyState() { |
| 11394 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11395 | if (tm.isInEmergencyCall()) { |
| 11396 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11397 | return true; |
| 11398 | } |
| 11399 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11400 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11401 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11402 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11403 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11404 | return true; |
| 11405 | } |
| 11406 | } |
| 11407 | |
| 11408 | return false; |
| 11409 | } |
| 11410 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11411 | /** |
| 11412 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11413 | * @param packageName name of package to be allowlisted |
| 11414 | * @param context |
| 11415 | */ |
| 11416 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11417 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11418 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11419 | } |
| 11420 | |
| 11421 | /** |
| 11422 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11423 | * @param packageName name of package to remove from allowlist |
| 11424 | * @param context |
| 11425 | */ |
| 11426 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11427 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11428 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11429 | } |
| 11430 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11431 | /** |
| 11432 | * Thermal mitigation request to control functionalities at modem. |
| 11433 | * |
| 11434 | * @param subId the id of the subscription. |
| 11435 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11436 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11437 | * |
| 11438 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11439 | */ |
| 11440 | @Override |
| 11441 | @ThermalMitigationResult |
| 11442 | public int sendThermalMitigationRequest( |
| 11443 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11444 | ThermalMitigationRequest thermalMitigationRequest, |
| 11445 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11446 | enforceModifyPermission(); |
| 11447 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11448 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11449 | |
| 11450 | enforceTelephonyFeatureWithException(callingPackage, |
| 11451 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11452 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11453 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11454 | .contains(callingPackage)) { |
| 11455 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11456 | + "calling package: " + callingPackage); |
| 11457 | } |
| 11458 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11459 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11460 | final long identity = Binder.clearCallingIdentity(); |
| 11461 | |
| 11462 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11463 | try { |
| 11464 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11465 | switch (thermalMitigationAction) { |
| 11466 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11467 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11468 | handleDataThrottlingRequest(subId, |
| 11469 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11470 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11471 | break; |
| 11472 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11473 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11474 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11475 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11476 | } |
| 11477 | |
| 11478 | // Ensure that radio is on. If not able to power on due to phone being |
| 11479 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11480 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11481 | thermalMitigationResult = |
| 11482 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11483 | break; |
| 11484 | } |
| 11485 | |
| 11486 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11487 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11488 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11489 | break; |
| 11490 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11491 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11492 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11493 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11494 | } |
| 11495 | |
| 11496 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11497 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11498 | Phone phone = getPhone(subId); |
| 11499 | if (phone == null) { |
| 11500 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11501 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11502 | break; |
| 11503 | } |
| 11504 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11505 | TelephonyConnectionService service = |
| 11506 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11507 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11508 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11509 | thermalMitigationResult = |
| 11510 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11511 | break; |
| 11512 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11513 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11514 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11515 | break; |
| 11516 | } |
| 11517 | } else { |
| 11518 | thermalMitigationResult = |
| 11519 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11520 | break; |
| 11521 | } |
| 11522 | |
| 11523 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11524 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11525 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11526 | thermalMitigationResult = |
| 11527 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11528 | break; |
| 11529 | } |
| 11530 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11531 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11532 | break; |
| 11533 | default: |
| 11534 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11535 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11536 | } |
| 11537 | } catch (IllegalArgumentException e) { |
| 11538 | throw e; |
| 11539 | } catch (Exception e) { |
| 11540 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11541 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11542 | } finally { |
| 11543 | Binder.restoreCallingIdentity(identity); |
| 11544 | } |
| 11545 | |
| 11546 | if (DBG) { |
| 11547 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11548 | + thermalMitigationResult); |
| 11549 | } |
| 11550 | |
| 11551 | return thermalMitigationResult; |
| 11552 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11553 | |
| 11554 | /** |
| 11555 | * Set the GbaService Package Name that Telephony will bind to. |
| 11556 | * |
| 11557 | * @param subId The sim that the GbaService is associated with. |
| 11558 | * @param packageName The name of the package to be replaced with. |
| 11559 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11560 | */ |
| 11561 | @Override |
| 11562 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11563 | enforceModifyPermission(); |
| 11564 | |
| 11565 | final long identity = Binder.clearCallingIdentity(); |
| 11566 | try { |
| 11567 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 11568 | } finally { |
| 11569 | Binder.restoreCallingIdentity(identity); |
| 11570 | } |
| 11571 | } |
| 11572 | |
| 11573 | /** |
| 11574 | * Return the package name of the currently bound GbaService. |
| 11575 | * |
| 11576 | * @param subId The sim that the GbaService is associated with. |
| 11577 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11578 | */ |
| 11579 | @Override |
| 11580 | public String getBoundGbaService(int subId) { |
| 11581 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11582 | |
| 11583 | final long identity = Binder.clearCallingIdentity(); |
| 11584 | try { |
| 11585 | return getGbaManager(subId).getServicePackage(); |
| 11586 | } finally { |
| 11587 | Binder.restoreCallingIdentity(identity); |
| 11588 | } |
| 11589 | } |
| 11590 | |
| 11591 | /** |
| 11592 | * Set the release time for telephony to unbind GbaService. |
| 11593 | * |
| 11594 | * @param subId The sim that the GbaService is associated with. |
| 11595 | * @param interval The release time to unbind GbaService by millisecond. |
| 11596 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11597 | */ |
| 11598 | @Override |
| 11599 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11600 | enforceModifyPermission(); |
| 11601 | |
| 11602 | final long identity = Binder.clearCallingIdentity(); |
| 11603 | try { |
| 11604 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11605 | } finally { |
| 11606 | Binder.restoreCallingIdentity(identity); |
| 11607 | } |
| 11608 | } |
| 11609 | |
| 11610 | /** |
| 11611 | * Return the release time for telephony to unbind GbaService. |
| 11612 | * |
| 11613 | * @param subId The sim that the GbaService is associated with. |
| 11614 | * @return The release time to unbind GbaService by millisecond. |
| 11615 | */ |
| 11616 | @Override |
| 11617 | public int getGbaReleaseTime(int subId) { |
| 11618 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11619 | |
| 11620 | final long identity = Binder.clearCallingIdentity(); |
| 11621 | try { |
| 11622 | return getGbaManager(subId).getReleaseTime(); |
| 11623 | } finally { |
| 11624 | Binder.restoreCallingIdentity(identity); |
| 11625 | } |
| 11626 | } |
| 11627 | |
| 11628 | private GbaManager getGbaManager(int subId) { |
| 11629 | GbaManager instance = GbaManager.getInstance(subId); |
| 11630 | if (instance == null) { |
| 11631 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11632 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11633 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11634 | } |
| 11635 | return instance; |
| 11636 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11637 | |
| 11638 | /** |
| 11639 | * indicate whether the device and the carrier can support |
| 11640 | * RCS VoLTE single registration. |
| 11641 | */ |
| 11642 | @Override |
| 11643 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11644 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11645 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11646 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11647 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11648 | |
| 11649 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11650 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11651 | } |
| 11652 | |
| 11653 | final long identity = Binder.clearCallingIdentity(); |
| 11654 | try { |
| 11655 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11656 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11657 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11658 | if (isCapable != null) { |
| 11659 | return isCapable; |
| 11660 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11661 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11662 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11663 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11664 | } finally { |
| 11665 | Binder.restoreCallingIdentity(identity); |
| 11666 | } |
| 11667 | } |
| 11668 | |
| 11669 | /** |
| 11670 | * Register RCS provisioning callback. |
| 11671 | */ |
| 11672 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11673 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11674 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11675 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11676 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11677 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11678 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11679 | |
| 11680 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11681 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11682 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11683 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11684 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11685 | Binder.getCallingUserHandle())) { |
| 11686 | if (!isImsAvailableOnDevice()) { |
| 11687 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11688 | "IMS not available on device."); |
| 11689 | } |
| 11690 | } else { |
| 11691 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11692 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11693 | } |
| 11694 | |
| 11695 | final long identity = Binder.clearCallingIdentity(); |
| 11696 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11697 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11698 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11699 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11700 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11701 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11702 | } finally { |
| 11703 | Binder.restoreCallingIdentity(identity); |
| 11704 | } |
| 11705 | } |
| 11706 | |
| 11707 | /** |
| 11708 | * Unregister RCS provisioning callback. |
| 11709 | */ |
| 11710 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11711 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11712 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11713 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11714 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11715 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11716 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11717 | |
| 11718 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11719 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11720 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11721 | |
| 11722 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11723 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11724 | Binder.getCallingUserHandle())) { |
| 11725 | if (!isImsAvailableOnDevice()) { |
| 11726 | // operation failed silently |
| 11727 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11728 | return; |
| 11729 | } |
| 11730 | } else { |
| 11731 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11732 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11733 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11734 | } |
| 11735 | |
| 11736 | final long identity = Binder.clearCallingIdentity(); |
| 11737 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11738 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11739 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11740 | } finally { |
| 11741 | Binder.restoreCallingIdentity(identity); |
| 11742 | } |
| 11743 | } |
| 11744 | |
| 11745 | /** |
| 11746 | * trigger RCS reconfiguration. |
| 11747 | */ |
| 11748 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11749 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11750 | "triggerRcsReconfiguration", |
| 11751 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11752 | |
| 11753 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11754 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11755 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11756 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11757 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11758 | Binder.getCallingUserHandle())) { |
| 11759 | if (!isImsAvailableOnDevice()) { |
| 11760 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11761 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11762 | throw new IllegalStateException("IMS not available on device."); |
| 11763 | } |
| 11764 | } else { |
| 11765 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11766 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11767 | } |
| 11768 | |
| 11769 | final long identity = Binder.clearCallingIdentity(); |
| 11770 | try { |
| 11771 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11772 | } finally { |
| 11773 | Binder.restoreCallingIdentity(identity); |
| 11774 | } |
| 11775 | } |
| 11776 | |
| 11777 | /** |
| 11778 | * Provide the client configuration parameters of the RCS application. |
| 11779 | */ |
| 11780 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11781 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11782 | "setRcsClientConfiguration", |
| 11783 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11784 | |
| 11785 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11786 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11787 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11788 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11789 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11790 | Binder.getCallingUserHandle())) { |
| 11791 | if (!isImsAvailableOnDevice()) { |
| 11792 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11793 | "IMS not available on device."); |
| 11794 | } |
| 11795 | } else { |
| 11796 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11797 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11798 | } |
| 11799 | |
| 11800 | final long identity = Binder.clearCallingIdentity(); |
| 11801 | |
| 11802 | try { |
| 11803 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11804 | if (configBinder == null) { |
| 11805 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11806 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11807 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11808 | } else { |
| 11809 | configBinder.setRcsClientConfiguration(rcc); |
| 11810 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11811 | |
| 11812 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11813 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11814 | } catch (RemoteException e) { |
| 11815 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11816 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11817 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11818 | } finally { |
| 11819 | Binder.restoreCallingIdentity(identity); |
| 11820 | } |
| 11821 | } |
| 11822 | |
| 11823 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11824 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11825 | */ |
| 11826 | @Override |
| 11827 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11828 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11829 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11830 | |
| 11831 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11832 | } |
| 11833 | |
| 11834 | /** |
| 11835 | * Gets the test mode for RCS VoLTE single registration. |
| 11836 | */ |
| 11837 | @Override |
| 11838 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11839 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11840 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11841 | |
| 11842 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11843 | } |
| 11844 | |
| 11845 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11846 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11847 | */ |
| 11848 | @Override |
| 11849 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11850 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11851 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11852 | enforceModifyPermission(); |
| 11853 | |
| 11854 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11855 | : Boolean.parseBoolean(enabledStr); |
| 11856 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11857 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11858 | } |
| 11859 | |
| 11860 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11861 | * Sends a device to device communication message. Only usable via shell. |
| 11862 | * @param message message to send. |
| 11863 | * @param value message value. |
| 11864 | */ |
| 11865 | @Override |
| 11866 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11867 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11868 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11869 | enforceModifyPermission(); |
| 11870 | |
| 11871 | final long identity = Binder.clearCallingIdentity(); |
| 11872 | try { |
| 11873 | TelephonyConnectionService service = |
| 11874 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11875 | if (service == null) { |
| 11876 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11877 | return; |
| 11878 | } |
| 11879 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11880 | } finally { |
| 11881 | Binder.restoreCallingIdentity(identity); |
| 11882 | } |
| 11883 | } |
| 11884 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11885 | /** |
| 11886 | * Sets the specified device to device transport active. |
| 11887 | * @param transport The transport to set active. |
| 11888 | */ |
| 11889 | @Override |
| 11890 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11891 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11892 | "setActiveDeviceToDeviceTransport"); |
| 11893 | enforceModifyPermission(); |
| 11894 | |
| 11895 | final long identity = Binder.clearCallingIdentity(); |
| 11896 | try { |
| 11897 | TelephonyConnectionService service = |
| 11898 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11899 | if (service == null) { |
| 11900 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11901 | return; |
| 11902 | } |
| 11903 | service.setActiveDeviceToDeviceTransport(transport); |
| 11904 | } finally { |
| 11905 | Binder.restoreCallingIdentity(identity); |
| 11906 | } |
| 11907 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11908 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11909 | @Override |
| 11910 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11911 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11912 | "setDeviceToDeviceForceEnabled"); |
| 11913 | |
| 11914 | final long identity = Binder.clearCallingIdentity(); |
| 11915 | try { |
| 11916 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11917 | p -> { |
| 11918 | Phone thePhone = p.getImsPhone(); |
| 11919 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11920 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11921 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11922 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11923 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11924 | (ImsPhoneCallTracker) tracker; |
| 11925 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11926 | } |
| 11927 | } |
| 11928 | } |
| 11929 | ); |
| 11930 | } finally { |
| 11931 | Binder.restoreCallingIdentity(identity); |
| 11932 | } |
| 11933 | } |
| 11934 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11935 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11936 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11937 | */ |
| 11938 | @Override |
| 11939 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11940 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11941 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11942 | } |
| 11943 | |
| 11944 | /** |
| 11945 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11946 | */ |
| 11947 | @Override |
| 11948 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11949 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11950 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11951 | enforceModifyPermission(); |
| 11952 | |
| 11953 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11954 | : Boolean.parseBoolean(enabledStr); |
| 11955 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11956 | subId, enabled); |
| 11957 | } |
| 11958 | |
| 11959 | /** |
| 11960 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11961 | */ |
| 11962 | @Override |
| 11963 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11964 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11965 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11966 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11967 | |
| 11968 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11969 | * Overrides the ims feature validation result |
| 11970 | */ |
| 11971 | @Override |
| 11972 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11973 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11974 | "setImsFeatureValidationOverride"); |
| 11975 | |
| 11976 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11977 | : Boolean.parseBoolean(enabledStr); |
| 11978 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11979 | subId, enabled); |
| 11980 | } |
| 11981 | |
| 11982 | /** |
| 11983 | * Gets the ims feature validation override value |
| 11984 | */ |
| 11985 | @Override |
| 11986 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11987 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11988 | "getImsFeatureValidationOverride"); |
| 11989 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11990 | } |
| 11991 | |
| 11992 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11993 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11994 | * their mobile plan. |
| 11995 | */ |
| 11996 | @Override |
| 11997 | public String getMobileProvisioningUrl() { |
| 11998 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11999 | final long identity = Binder.clearCallingIdentity(); |
| 12000 | try { |
| 12001 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12002 | } finally { |
| 12003 | Binder.restoreCallingIdentity(identity); |
| 12004 | } |
| 12005 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12006 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12007 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12008 | * Get the EAB contact from the EAB database. |
| 12009 | */ |
| 12010 | @Override |
| 12011 | public String getContactFromEab(String contact) { |
| 12012 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12013 | enforceModifyPermission(); |
| 12014 | final long identity = Binder.clearCallingIdentity(); |
| 12015 | try { |
| 12016 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12017 | } finally { |
| 12018 | Binder.restoreCallingIdentity(identity); |
| 12019 | } |
| 12020 | } |
| 12021 | |
| 12022 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12023 | * Get the EAB capability from the EAB database. |
| 12024 | */ |
| 12025 | @Override |
| 12026 | public String getCapabilityFromEab(String contact) { |
| 12027 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12028 | enforceModifyPermission(); |
| 12029 | final long identity = Binder.clearCallingIdentity(); |
| 12030 | try { |
| 12031 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12032 | } finally { |
| 12033 | Binder.restoreCallingIdentity(identity); |
| 12034 | } |
| 12035 | } |
| 12036 | |
| 12037 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12038 | * Remove the EAB contacts from the EAB database. |
| 12039 | */ |
| 12040 | @Override |
| 12041 | public int removeContactFromEab(int subId, String contacts) { |
| 12042 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12043 | enforceModifyPermission(); |
| 12044 | final long identity = Binder.clearCallingIdentity(); |
| 12045 | try { |
| 12046 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12047 | } finally { |
| 12048 | Binder.restoreCallingIdentity(identity); |
| 12049 | } |
| 12050 | } |
| 12051 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12052 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12053 | public boolean getDeviceUceEnabled() { |
| 12054 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12055 | final long identity = Binder.clearCallingIdentity(); |
| 12056 | try { |
| 12057 | return mApp.getDeviceUceEnabled(); |
| 12058 | } finally { |
| 12059 | Binder.restoreCallingIdentity(identity); |
| 12060 | } |
| 12061 | } |
| 12062 | |
| 12063 | @Override |
| 12064 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12065 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12066 | final long identity = Binder.clearCallingIdentity(); |
| 12067 | try { |
| 12068 | mApp.setDeviceUceEnabled(isEnabled); |
| 12069 | } finally { |
| 12070 | Binder.restoreCallingIdentity(identity); |
| 12071 | } |
| 12072 | } |
| 12073 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12074 | /** |
| 12075 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12076 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12077 | */ |
| 12078 | // Used for SHELL command only right now. |
| 12079 | @Override |
| 12080 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12081 | List<String> featureTags) { |
| 12082 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12083 | "addUceRegistrationOverrideShell"); |
| 12084 | final long identity = Binder.clearCallingIdentity(); |
| 12085 | try { |
| 12086 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12087 | new ArraySet<>(featureTags)); |
| 12088 | } catch (ImsException e) { |
| 12089 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12090 | } finally { |
| 12091 | Binder.restoreCallingIdentity(identity); |
| 12092 | } |
| 12093 | } |
| 12094 | |
| 12095 | /** |
| 12096 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12097 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12098 | */ |
| 12099 | // Used for SHELL command only right now. |
| 12100 | @Override |
| 12101 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12102 | List<String> featureTags) { |
| 12103 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12104 | "removeUceRegistrationOverrideShell"); |
| 12105 | final long identity = Binder.clearCallingIdentity(); |
| 12106 | try { |
| 12107 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12108 | new ArraySet<>(featureTags)); |
| 12109 | } catch (ImsException e) { |
| 12110 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12111 | } finally { |
| 12112 | Binder.restoreCallingIdentity(identity); |
| 12113 | } |
| 12114 | } |
| 12115 | |
| 12116 | /** |
| 12117 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12118 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12119 | */ |
| 12120 | // Used for SHELL command only right now. |
| 12121 | @Override |
| 12122 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12123 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12124 | "clearUceRegistrationOverrideShell"); |
| 12125 | final long identity = Binder.clearCallingIdentity(); |
| 12126 | try { |
| 12127 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12128 | } catch (ImsException e) { |
| 12129 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12130 | } finally { |
| 12131 | Binder.restoreCallingIdentity(identity); |
| 12132 | } |
| 12133 | } |
| 12134 | |
| 12135 | /** |
| 12136 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12137 | */ |
| 12138 | // Used for SHELL command only right now. |
| 12139 | @Override |
| 12140 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12141 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12142 | "getLatestRcsContactUceCapabilityShell"); |
| 12143 | final long identity = Binder.clearCallingIdentity(); |
| 12144 | try { |
| 12145 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12146 | } catch (ImsException e) { |
| 12147 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12148 | } finally { |
| 12149 | Binder.restoreCallingIdentity(identity); |
| 12150 | } |
| 12151 | } |
| 12152 | |
| 12153 | /** |
| 12154 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12155 | * device does not have an active PUBLISH. |
| 12156 | */ |
| 12157 | // Used for SHELL command only right now. |
| 12158 | @Override |
| 12159 | public String getLastUcePidfXmlShell(int subId) { |
| 12160 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12161 | final long identity = Binder.clearCallingIdentity(); |
| 12162 | try { |
| 12163 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12164 | } catch (ImsException e) { |
| 12165 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12166 | } finally { |
| 12167 | Binder.restoreCallingIdentity(identity); |
| 12168 | } |
| 12169 | } |
| 12170 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12171 | /** |
| 12172 | * Remove UCE requests cannot be sent to the network status. |
| 12173 | */ |
| 12174 | // Used for SHELL command only right now. |
| 12175 | @Override |
| 12176 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12177 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12178 | final long identity = Binder.clearCallingIdentity(); |
| 12179 | try { |
| 12180 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12181 | } catch (ImsException e) { |
| 12182 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12183 | } finally { |
| 12184 | Binder.restoreCallingIdentity(identity); |
| 12185 | } |
| 12186 | } |
| 12187 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12188 | /** |
| 12189 | * Remove UCE requests cannot be sent to the network status. |
| 12190 | */ |
| 12191 | // Used for SHELL command only. |
| 12192 | @Override |
| 12193 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12194 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12195 | final long identity = Binder.clearCallingIdentity(); |
| 12196 | try { |
| 12197 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12198 | } catch (ImsException e) { |
| 12199 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12200 | } finally { |
| 12201 | Binder.restoreCallingIdentity(identity); |
| 12202 | } |
| 12203 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12204 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12205 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12206 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12207 | String callingPackage) { |
| 12208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12209 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12210 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12211 | enforceTelephonyFeatureWithException(callingPackage, |
| 12212 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12213 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12214 | final int callingUid = Binder.getCallingUid(); |
| 12215 | // Verify that tha callingPackage belongs to the calling UID |
| 12216 | mApp.getSystemService(AppOpsManager.class) |
| 12217 | .checkPackage(callingUid, callingPackage); |
| 12218 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12219 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12220 | |
| 12221 | final long identity = Binder.clearCallingIdentity(); |
| 12222 | try { |
| 12223 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12224 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12225 | |
| 12226 | if (result instanceof IllegalStateException) { |
| 12227 | throw (IllegalStateException) result; |
| 12228 | } |
| 12229 | } finally { |
| 12230 | Binder.restoreCallingIdentity(identity); |
| 12231 | } |
| 12232 | } |
| 12233 | |
| 12234 | @Override |
| 12235 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12236 | String callingPackage) { |
| 12237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12238 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12239 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12240 | enforceTelephonyFeatureWithException(callingPackage, |
| 12241 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12242 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12243 | final int callingUid = Binder.getCallingUid(); |
| 12244 | // Verify that tha callingPackage belongs to the calling UID |
| 12245 | mApp.getSystemService(AppOpsManager.class) |
| 12246 | .checkPackage(callingUid, callingPackage); |
| 12247 | |
| 12248 | final long identity = Binder.clearCallingIdentity(); |
| 12249 | try { |
| 12250 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12251 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12252 | |
| 12253 | if (result instanceof IllegalStateException) { |
| 12254 | throw (IllegalStateException) result; |
| 12255 | } |
| 12256 | } finally { |
| 12257 | Binder.restoreCallingIdentity(identity); |
| 12258 | } |
| 12259 | } |
| 12260 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12261 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12262 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12263 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 12264 | // phone/system process do not have further restriction on request |
| 12265 | return; |
| 12266 | } |
| 12267 | |
| 12268 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12269 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12270 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12271 | context.enforceCallingOrSelfPermission( |
| 12272 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12273 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12274 | } |
| 12275 | |
| 12276 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12277 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12278 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12279 | || info.isEnabled()) { |
| 12280 | throw new IllegalArgumentException( |
| 12281 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12282 | } |
| 12283 | |
| 12284 | // Thresholds length for each RAN need in range. This has been validated in |
| 12285 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12286 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12287 | final int[] thresholds = info.getThresholds(); |
| 12288 | Objects.requireNonNull(thresholds); |
| 12289 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12290 | || thresholds.length |
| 12291 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12292 | throw new IllegalArgumentException( |
| 12293 | "thresholds length is out of range: " + thresholds.length); |
| 12294 | } |
| 12295 | } |
| 12296 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12297 | |
| 12298 | /** |
| 12299 | * Gets the current phone capability. |
| 12300 | * |
| 12301 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12302 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12303 | * It's used to evaluate possible phone config change, for example from single |
| 12304 | * SIM device to multi-SIM device. |
| 12305 | */ |
| 12306 | @Override |
| 12307 | public PhoneCapability getPhoneCapability() { |
| 12308 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12309 | |
| 12310 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12311 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12312 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12313 | final long identity = Binder.clearCallingIdentity(); |
| 12314 | try { |
| 12315 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12316 | } finally { |
| 12317 | Binder.restoreCallingIdentity(identity); |
| 12318 | } |
| 12319 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12320 | |
| 12321 | /** |
| 12322 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12323 | * required to be done shortly after the API is invoked. |
| 12324 | */ |
| 12325 | @Override |
| 12326 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12327 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12328 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12329 | enforceRebootPermission(); |
| 12330 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12331 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12332 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12333 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12334 | final long identity = Binder.clearCallingIdentity(); |
| 12335 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12336 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12337 | } finally { |
| 12338 | Binder.restoreCallingIdentity(identity); |
| 12339 | } |
| 12340 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12341 | |
| 12342 | /** |
| 12343 | * Request to get the current slicing configuration including URSP rules and |
| 12344 | * NSSAIs (configured, allowed and rejected). |
| 12345 | * |
| 12346 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12347 | */ |
| 12348 | @Override |
| 12349 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12350 | TelephonyPermissions |
| 12351 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12352 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12353 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12354 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12355 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12356 | "getSlicingConfig"); |
| 12357 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12358 | final long identity = Binder.clearCallingIdentity(); |
| 12359 | try { |
| 12360 | Phone phone = getDefaultPhone(); |
| 12361 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12362 | } finally { |
| 12363 | Binder.restoreCallingIdentity(identity); |
| 12364 | } |
| 12365 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12366 | |
| 12367 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12368 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12369 | * |
| 12370 | * @param capability The premium capability to check. |
| 12371 | * @param subId The subId to check the premium capability for. |
| 12372 | * |
| 12373 | * @return Whether the given premium capability is available to purchase. |
| 12374 | */ |
| 12375 | @Override |
| 12376 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12377 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12378 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12379 | log("Premium capability " |
| 12380 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12381 | + " is not available for purchase due to missing permissions."); |
| 12382 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12383 | + "permission READ_BASIC_PHONE_STATE."); |
| 12384 | } |
| 12385 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12386 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12387 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12388 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12389 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12390 | if (phone == null) { |
| 12391 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12392 | return false; |
| 12393 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12394 | final long identity = Binder.clearCallingIdentity(); |
| 12395 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12396 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12397 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12398 | } finally { |
| 12399 | Binder.restoreCallingIdentity(identity); |
| 12400 | } |
| 12401 | } |
| 12402 | |
| 12403 | /** |
| 12404 | * Purchase the given premium capability from the carrier. |
| 12405 | * |
| 12406 | * @param capability The premium capability to purchase. |
| 12407 | * @param callback The result of the purchase request. |
| 12408 | * @param subId The subId to purchase the premium capability for. |
| 12409 | */ |
| 12410 | @Override |
| 12411 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12412 | log("purchasePremiumCapability: capability=" |
| 12413 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12414 | + getCurrentPackageName()); |
| 12415 | |
| 12416 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12417 | mApp, "purchasePremiumCapability")) { |
| 12418 | log("purchasePremiumCapability " |
| 12419 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12420 | + " failed due to missing permissions."); |
| 12421 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12422 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12423 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12424 | mApp, "purchasePremiumCapability")) { |
| 12425 | log("purchasePremiumCapability " |
| 12426 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12427 | + " failed due to missing permissions."); |
| 12428 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12429 | } |
| 12430 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12431 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12432 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12433 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12434 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12435 | if (phone == null) { |
| 12436 | try { |
| 12437 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12438 | callback.accept(result); |
| 12439 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12440 | } catch (RemoteException e) { |
| 12441 | String logStr = "Purchase premium capability " |
| 12442 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12443 | + " failed due to RemoteException handling null phone: " + e; |
| 12444 | if (DBG) log(logStr); |
| 12445 | AnomalyReporter.reportAnomaly( |
| 12446 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12447 | } |
| 12448 | return; |
| 12449 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12450 | |
| 12451 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12452 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12453 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12454 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12455 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12456 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12457 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12458 | |
| 12459 | boolean isVisible = false; |
| 12460 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12461 | if (am != null) { |
| 12462 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12463 | if (processes != null) { |
| 12464 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12465 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12466 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12467 | if (process.processName.equals(callingProcess) && process.importance |
| 12468 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12469 | isVisible = true; |
| 12470 | break; |
| 12471 | } |
| 12472 | } |
| 12473 | } |
| 12474 | } |
| 12475 | |
| 12476 | if (!isVisible) { |
| 12477 | try { |
| 12478 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12479 | callback.accept(result); |
| 12480 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12481 | } catch (RemoteException e) { |
| 12482 | String logStr = "Purchase premium capability " |
| 12483 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12484 | + " failed due to RemoteException handling background application: " + e; |
| 12485 | if (DBG) log(logStr); |
| 12486 | AnomalyReporter.reportAnomaly( |
| 12487 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12488 | } |
| 12489 | return; |
| 12490 | } |
| 12491 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12492 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12493 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12494 | } |
| 12495 | |
| 12496 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12497 | * Register an IMS connection state callback |
| 12498 | */ |
| 12499 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12500 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12501 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12502 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12503 | // ImsMmTelManager |
| 12504 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12505 | TelephonyPermissions |
| 12506 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12507 | mApp, subId, "registerImsStateCallback"); |
| 12508 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12509 | // ImsRcsManager or SipDelegateManager |
| 12510 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12511 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12512 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12513 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12514 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12515 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12516 | } |
| 12517 | |
| 12518 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12519 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12520 | "IMS not available on device."); |
| 12521 | } |
| 12522 | |
| 12523 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12524 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12525 | } |
| 12526 | |
| 12527 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12528 | if (controller == null) { |
| 12529 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12530 | "IMS not available on device."); |
| 12531 | } |
| 12532 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12533 | if (callingPackage == null) { |
| 12534 | callingPackage = getCurrentPackageName(); |
| 12535 | } |
| 12536 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12537 | final long token = Binder.clearCallingIdentity(); |
| 12538 | try { |
| 12539 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12540 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12541 | } catch (ImsException e) { |
| 12542 | throw new ServiceSpecificException(e.getCode()); |
| 12543 | } finally { |
| 12544 | Binder.restoreCallingIdentity(token); |
| 12545 | } |
| 12546 | } |
| 12547 | |
| 12548 | /** |
| 12549 | * Unregister an IMS connection state callback |
| 12550 | */ |
| 12551 | @Override |
| 12552 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12553 | final long token = Binder.clearCallingIdentity(); |
| 12554 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12555 | if (controller == null) { |
| 12556 | return; |
| 12557 | } |
| 12558 | try { |
| 12559 | controller.unregisterImsStateCallback(cb); |
| 12560 | } finally { |
| 12561 | Binder.restoreCallingIdentity(token); |
| 12562 | } |
| 12563 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12564 | |
| 12565 | /** |
| 12566 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12567 | * |
| 12568 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 12569 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 12570 | * SecurityException. |
| 12571 | * If there is current registered network this value will be same as the registered cell |
| 12572 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12573 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12574 | * it will be cleared and null will be returned. |
| 12575 | * |
| 12576 | */ |
| 12577 | @Override |
| 12578 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12579 | String callingFeatureId) { |
| 12580 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12581 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12582 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12583 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12584 | .setCallingPackage(callingPackage) |
| 12585 | .setCallingFeatureId(callingFeatureId) |
| 12586 | .setCallingPid(Binder.getCallingPid()) |
| 12587 | .setCallingUid(Binder.getCallingUid()) |
| 12588 | .setMethod("getLastKnownCellIdentity") |
| 12589 | .setLogAsInfo(true) |
| 12590 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12591 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12592 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12593 | .build()); |
| 12594 | |
| 12595 | boolean hasFinePermission = |
| 12596 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12597 | if (!hasFinePermission |
| 12598 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12599 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12600 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12601 | } |
| 12602 | |
| 12603 | final long identity = Binder.clearCallingIdentity(); |
| 12604 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12605 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12606 | if (sst == null) return null; |
| 12607 | return sst.getLastKnownCellIdentity(); |
| 12608 | } finally { |
| 12609 | Binder.restoreCallingIdentity(identity); |
| 12610 | } |
| 12611 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12612 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12613 | /** |
| 12614 | * Sets the modem service class Name that Telephony will bind to. |
| 12615 | * |
| 12616 | * @param serviceName The class name of the modem service. |
| 12617 | * @return true if the operation is succeed, otherwise false. |
| 12618 | */ |
| 12619 | public boolean setModemService(String serviceName) { |
| 12620 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12621 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12623 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12624 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12625 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12626 | } |
| 12627 | |
| 12628 | /** |
| 12629 | * Return the class name of the currently bounded modem service. |
| 12630 | * |
| 12631 | * @return the class name of the modem service. |
| 12632 | */ |
| 12633 | public String getModemService() { |
| 12634 | String result; |
| 12635 | Log.d(LOG_TAG, "getModemService"); |
| 12636 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12637 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12638 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12639 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12640 | "getModemService"); |
| 12641 | result = mPhoneConfigurationManager.getModemService(); |
| 12642 | Log.d(LOG_TAG, "result = " + result); |
| 12643 | return result; |
| 12644 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12645 | |
| 12646 | @Override |
| 12647 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12648 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12649 | mApp.enforceCallingOrSelfPermission( |
| 12650 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12651 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12652 | |
| 12653 | final long identity = Binder.clearCallingIdentity(); |
| 12654 | try { |
| 12655 | Phone phone = getPhone(subId); |
| 12656 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12657 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12658 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12659 | phone.setVoiceServiceStateOverride(hasService); |
| 12660 | } finally { |
| 12661 | Binder.restoreCallingIdentity(identity); |
| 12662 | } |
| 12663 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12664 | |
| 12665 | /** |
| 12666 | * set removable eSIM as default eUICC. |
| 12667 | * |
| 12668 | * @hide |
| 12669 | */ |
| 12670 | @Override |
| 12671 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12672 | enforceModifyPermission(); |
| 12673 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12674 | |
| 12675 | final long identity = Binder.clearCallingIdentity(); |
| 12676 | try { |
| 12677 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12678 | } finally { |
| 12679 | Binder.restoreCallingIdentity(identity); |
| 12680 | } |
| 12681 | } |
| 12682 | |
| 12683 | /** |
| 12684 | * Returns whether the removable eSIM is default eUICC or not. |
| 12685 | * |
| 12686 | * @hide |
| 12687 | */ |
| 12688 | @Override |
| 12689 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12690 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12691 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12692 | |
| 12693 | final long identity = Binder.clearCallingIdentity(); |
| 12694 | try { |
| 12695 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12696 | } finally { |
| 12697 | Binder.restoreCallingIdentity(identity); |
| 12698 | } |
| 12699 | } |
| 12700 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12701 | /** |
| 12702 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12703 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12704 | * application currently configured for this user. |
| 12705 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12706 | * {@code null} if the functionality is not supported. |
| 12707 | * @hide |
| 12708 | */ |
| 12709 | @Override |
| 12710 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12711 | boolean updateIfNeeded) { |
| 12712 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12713 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12714 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12715 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12716 | "getDefaultRespondViaMessageApplication"); |
| 12717 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12718 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12719 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12720 | UserHandle userHandle = null; |
| 12721 | final long identity = Binder.clearCallingIdentity(); |
| 12722 | try { |
| 12723 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12724 | } finally { |
| 12725 | Binder.restoreCallingIdentity(identity); |
| 12726 | } |
| 12727 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12728 | updateIfNeeded, userHandle); |
| 12729 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12730 | |
| 12731 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12732 | * Set whether the device is able to connect with null ciphering or integrity |
| 12733 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12734 | * and all new subscriptions after this. |
| 12735 | * |
| 12736 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12737 | * @hide |
| 12738 | */ |
| 12739 | @Override |
| 12740 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12741 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12742 | enforceModifyPermission(); |
| 12743 | checkForNullCipherAndIntegritySupport(); |
| 12744 | |
| 12745 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12746 | // for listening to these preference changes and applying them immediately. |
| 12747 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12748 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12749 | editor.apply(); |
| 12750 | |
| 12751 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12752 | phone.handleNullCipherEnabledChange(); |
| 12753 | } |
| 12754 | } |
| 12755 | |
| 12756 | |
| 12757 | /** |
| 12758 | * Get whether the device is able to connect with null ciphering or integrity |
| 12759 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12760 | * the state of the radio. |
| 12761 | * |
| 12762 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12763 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12764 | * version for this feature. |
| 12765 | * @hide |
| 12766 | */ |
| 12767 | @Override |
| 12768 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12769 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12770 | enforceReadPermission(); |
| 12771 | checkForNullCipherAndIntegritySupport(); |
| 12772 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12773 | } |
| 12774 | |
| 12775 | private void checkForNullCipherAndIntegritySupport() { |
| 12776 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12777 | throw new UnsupportedOperationException( |
| 12778 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12779 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12780 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12781 | throw new UnsupportedOperationException( |
| 12782 | "Null cipher and integrity operations unsupported by modem"); |
| 12783 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12784 | } |
| 12785 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12786 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12787 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12788 | throw new UnsupportedOperationException( |
| 12789 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12790 | + "above"); |
| 12791 | } |
| 12792 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12793 | throw new UnsupportedOperationException( |
| 12794 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12795 | } |
| 12796 | } |
| 12797 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12798 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12799 | * Get the SIM state for the slot index. |
| 12800 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12801 | * |
| 12802 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12803 | */ |
| 12804 | @Override |
| 12805 | @SimState |
| 12806 | public int getSimStateForSlotIndex(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12807 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12808 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 12809 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12810 | IccCardConstants.State simState; |
| 12811 | if (slotIndex < 0) { |
| 12812 | simState = IccCardConstants.State.UNKNOWN; |
| 12813 | } else { |
| 12814 | Phone phone = null; |
| 12815 | try { |
| 12816 | phone = PhoneFactory.getPhone(slotIndex); |
| 12817 | } catch (IllegalStateException e) { |
| 12818 | // ignore |
| 12819 | } |
| 12820 | if (phone == null) { |
| 12821 | simState = IccCardConstants.State.UNKNOWN; |
| 12822 | } else { |
| 12823 | IccCard icc = phone.getIccCard(); |
| 12824 | if (icc == null) { |
| 12825 | simState = IccCardConstants.State.UNKNOWN; |
| 12826 | } else { |
| 12827 | simState = icc.getState(); |
| 12828 | } |
| 12829 | } |
| 12830 | } |
| 12831 | return simState.ordinal(); |
| 12832 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12833 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12834 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12835 | boolean enableLogcat, |
| 12836 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12837 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12838 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 12839 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 12840 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 12841 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 12842 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 12843 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 12844 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 12845 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12846 | Executors.newCachedThreadPool(), db, |
| 12847 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 12848 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12849 | } |
| 12850 | |
| 12851 | /** |
| 12852 | * Request telephony to persist state for debugging emergency call failures. |
| 12853 | * |
| 12854 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 12855 | * @param enableLogcat whether to collect logcat output |
| 12856 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12857 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12858 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12859 | */ |
| 12860 | @Override |
| 12861 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12862 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12863 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12864 | boolean enableTelephonyDump) { |
| 12865 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12866 | "persistEmergencyCallDiagnosticData"); |
| 12867 | final long identity = Binder.clearCallingIdentity(); |
| 12868 | try { |
| 12869 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12870 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12871 | |
| 12872 | } finally { |
| 12873 | Binder.restoreCallingIdentity(identity); |
| 12874 | } |
| 12875 | } |
| 12876 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12877 | /** |
| 12878 | * Get current cell broadcast ranges. |
| 12879 | */ |
| 12880 | @Override |
| 12881 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12882 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12883 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12884 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12885 | |
| 12886 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12887 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 12888 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12889 | final long identity = Binder.clearCallingIdentity(); |
| 12890 | try { |
| 12891 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12892 | } finally { |
| 12893 | Binder.restoreCallingIdentity(identity); |
| 12894 | } |
| 12895 | } |
| 12896 | |
| 12897 | /** |
| 12898 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12899 | * |
| 12900 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12901 | */ |
| 12902 | @Override |
| 12903 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12904 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12905 | @Nullable IIntegerConsumer callback) { |
| 12906 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12907 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12908 | |
| 12909 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12910 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 12911 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12912 | final long identity = Binder.clearCallingIdentity(); |
| 12913 | try { |
| 12914 | Phone phone = getPhoneFromSubId(subId); |
| 12915 | if (DBG) { |
| 12916 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12917 | } |
| 12918 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12919 | if (callback != null) { |
| 12920 | try { |
| 12921 | callback.accept(result); |
| 12922 | } catch (RemoteException e) { |
| 12923 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12924 | } |
| 12925 | } |
| 12926 | }); |
| 12927 | } finally { |
| 12928 | Binder.restoreCallingIdentity(identity); |
| 12929 | } |
| 12930 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12931 | |
| 12932 | /** |
| 12933 | * Returns whether the device supports the domain selection service. |
| 12934 | * |
| 12935 | * @return {@code true} if the device supports the domain selection service. |
| 12936 | */ |
| 12937 | @Override |
| 12938 | public boolean isDomainSelectionSupported() { |
| 12939 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12940 | "isDomainSelectionSupported"); |
| 12941 | |
| 12942 | final long identity = Binder.clearCallingIdentity(); |
| 12943 | try { |
| 12944 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12945 | } finally { |
| 12946 | Binder.restoreCallingIdentity(identity); |
| 12947 | } |
| 12948 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12949 | |
| 12950 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12951 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12952 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12953 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12954 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12955 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12956 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12957 | * {@code false} to disable. |
| 12958 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12959 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12960 | * |
| 12961 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12962 | */ |
| 12963 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12964 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12965 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12966 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 12967 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 12968 | @Override |
| 12969 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 12970 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 12971 | + ", resultData=" + resultData); |
| 12972 | boolean isAllowed = false; |
| 12973 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 12974 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 12975 | if (resultData != null |
| 12976 | && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 12977 | isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 12978 | } else { |
| 12979 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 12980 | } |
| 12981 | } else { |
| 12982 | result.accept(resultCode); |
| 12983 | return; |
| 12984 | } |
| 12985 | if (isAllowed) { |
| 12986 | mSatelliteController.requestSatelliteEnabled( |
| 12987 | subId, enableSatellite, enableDemoMode, callback); |
| 12988 | } else { |
| 12989 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 12990 | } |
| 12991 | } |
| 12992 | }; |
| 12993 | mSatelliteAccessController.requestIsSatelliteCommunicationAllowedForCurrentLocation( |
| 12994 | subId, resultReceiver); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12995 | } |
| 12996 | |
| 12997 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12998 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12999 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13000 | * @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] | 13001 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13002 | * 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] | 13003 | * |
| 13004 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13005 | */ |
| 13006 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13007 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 13008 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13009 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13010 | } |
| 13011 | |
| 13012 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13013 | * Request to get whether the satellite service demo mode is enabled. |
| 13014 | * |
| 13015 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 13016 | * is enabled for. |
| 13017 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13018 | * if the request is successful or an error code if the request failed. |
| 13019 | * |
| 13020 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13021 | */ |
| 13022 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13023 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 13024 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 13025 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13026 | } |
| 13027 | |
| 13028 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13029 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13030 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13031 | * @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] | 13032 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13033 | * 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] | 13034 | */ |
| 13035 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13036 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13037 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13038 | } |
| 13039 | |
| 13040 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13041 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13042 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13043 | * @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] | 13044 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13045 | * 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] | 13046 | * |
| 13047 | * @throws SecurityException if the caller doesn't have required permission. |
| 13048 | */ |
| 13049 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13050 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 13051 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13052 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13053 | } |
| 13054 | |
| 13055 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13056 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13057 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13058 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13059 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13060 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 13061 | * @param resultCallback The callback to get the result of the request. |
| 13062 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13063 | * |
| 13064 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13065 | */ |
| 13066 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13067 | public void startSatelliteTransmissionUpdates(int subId, |
| 13068 | @NonNull IIntegerConsumer resultCallback, |
| 13069 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13070 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 13071 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13072 | } |
| 13073 | |
| 13074 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13075 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13076 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13077 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13078 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 13079 | * @param resultCallback The callback to get the result of the request. |
| 13080 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 13081 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13082 | * |
| 13083 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13084 | */ |
| 13085 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13086 | public void stopSatelliteTransmissionUpdates(int subId, |
| 13087 | @NonNull IIntegerConsumer resultCallback, |
| 13088 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13089 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 13090 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13091 | } |
| 13092 | |
| 13093 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13094 | * Register the subscription with a satellite provider. |
| 13095 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13096 | * |
| 13097 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13098 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13099 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13100 | * @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] | 13101 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13102 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13103 | * @return The signal transport used by the caller to cancel the provision request, |
| 13104 | * or {@code null} if the request failed. |
| 13105 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13106 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13107 | */ |
| 13108 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13109 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13110 | @NonNull String token, @NonNull byte[] provisionData, |
| 13111 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13112 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13113 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 13114 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13115 | } |
| 13116 | |
| 13117 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13118 | * Unregister the device/subscription with the satellite provider. |
| 13119 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13120 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13121 | * should report as deprovisioned. |
| 13122 | * |
| 13123 | * @param subId The subId of the subscription to be deprovisioned. |
| 13124 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13125 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13126 | * |
| 13127 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13128 | */ |
| 13129 | @Override |
| 13130 | public void deprovisionSatelliteService(int subId, |
| 13131 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13132 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13133 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13134 | } |
| 13135 | |
| 13136 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13137 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13138 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13139 | * @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] | 13140 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13141 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13142 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13143 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13144 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13145 | */ |
| 13146 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13147 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
| 13148 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13149 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13150 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13151 | } |
| 13152 | |
| 13153 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13154 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13155 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13156 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13157 | * @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] | 13158 | * @param callback The callback that was passed to |
| 13159 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13160 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13161 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13162 | */ |
| 13163 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13164 | public void unregisterForSatelliteProvisionStateChanged( |
| 13165 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13166 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13167 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13168 | } |
| 13169 | |
| 13170 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13171 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13172 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13173 | * @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] | 13174 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13175 | * satellite provider if the request is successful or an error code if the |
| 13176 | * request failed. |
| 13177 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13178 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13179 | */ |
| 13180 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13181 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 13182 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13183 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13184 | } |
| 13185 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13186 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13187 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13188 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13189 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 13190 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13191 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13192 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13193 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13194 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13195 | */ |
| 13196 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13197 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13198 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13199 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13200 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13201 | } |
| 13202 | |
| 13203 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13204 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13205 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13206 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13207 | * @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] | 13208 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13209 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13210 | * |
| 13211 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13212 | */ |
| 13213 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13214 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13215 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13216 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13217 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13218 | } |
| 13219 | |
| 13220 | /** |
| 13221 | * Register to receive incoming datagrams over satellite. |
| 13222 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13223 | * @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] | 13224 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13225 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13226 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13227 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13228 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13229 | */ |
| 13230 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13231 | @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13232 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13233 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13234 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13235 | } |
| 13236 | |
| 13237 | /** |
| 13238 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13239 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13240 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13241 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 13242 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13243 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13244 | * |
| 13245 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13246 | */ |
| 13247 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13248 | public void unregisterForSatelliteDatagram(int subId, |
| 13249 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13250 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13251 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13252 | } |
| 13253 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13254 | /** |
| 13255 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13256 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13257 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13258 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13259 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13260 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13261 | * @param subId The subId of the subscription used for receiving datagrams. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13262 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13263 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13264 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13265 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13266 | @Override |
| 13267 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13268 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13269 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13270 | } |
| 13271 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13272 | /** |
| 13273 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13274 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13275 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13276 | * input to this method. Datagram received here will be passed down to modem without any |
| 13277 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13278 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13279 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 13280 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13281 | * SOS_SMS or LOCATION_SHARING. |
| 13282 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13283 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13284 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13285 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13286 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13287 | * |
| 13288 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13289 | */ |
| 13290 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13291 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 13292 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13293 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13294 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13295 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 13296 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13297 | } |
| 13298 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13299 | /** |
| 13300 | * Request to get whether satellite communication is allowed for the current location. |
| 13301 | * |
| 13302 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13303 | * allowed for the current location for. |
| 13304 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13305 | * for the current location if the request is successful or an error code |
| 13306 | * if the request failed. |
| 13307 | * |
| 13308 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13309 | */ |
| 13310 | @Override |
| 13311 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 13312 | @NonNull ResultReceiver result) { |
| 13313 | enforceSatelliteCommunicationPermission( |
| 13314 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 13315 | mSatelliteAccessController.requestIsSatelliteCommunicationAllowedForCurrentLocation( |
| 13316 | subId, result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13317 | } |
| 13318 | |
| 13319 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13320 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13321 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13322 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13323 | * @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] | 13324 | * be visible if the request is successful or an error code if the request failed. |
| 13325 | * |
| 13326 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13327 | */ |
| 13328 | @Override |
| 13329 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 13330 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 13331 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13332 | } |
| 13333 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13334 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13335 | * Inform that Device is aligned to satellite for demo mode. |
| 13336 | * |
| 13337 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 13338 | * @param isAligned {@code true} Device is aligned with the satellite for demo mode |
| 13339 | * {@code false} Device fails to align with the satellite for demo mode. |
| 13340 | * |
| 13341 | * @throws SecurityException if the caller doesn't have required permission. |
| 13342 | */ |
| 13343 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13344 | |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13345 | public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) { |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13346 | enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite"); |
Aishwarya Mallamapti | 697af85 | 2023-08-11 00:21:10 +0000 | [diff] [blame] | 13347 | mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13348 | } |
| 13349 | |
| 13350 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13351 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13352 | * by modem. |
| 13353 | * |
| 13354 | * @param subId The subId of the subscription to request for. |
| 13355 | * @param reason Reason for disallowing satellite communication for carrier. |
| 13356 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 13357 | * operation. |
| 13358 | * |
| 13359 | * @throws SecurityException if the caller doesn't have required permission. |
| 13360 | */ |
| 13361 | public void addSatelliteAttachRestrictionForCarrier(int subId, |
| 13362 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13363 | @NonNull IIntegerConsumer callback) { |
| 13364 | enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier"); |
| 13365 | final long identity = Binder.clearCallingIdentity(); |
| 13366 | try { |
| 13367 | mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback); |
| 13368 | } finally { |
| 13369 | Binder.restoreCallingIdentity(identity); |
| 13370 | } |
| 13371 | } |
| 13372 | |
| 13373 | /** |
| 13374 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13375 | * by modem. |
| 13376 | * |
| 13377 | * @param subId The subId of the subscription to request for. |
| 13378 | * @param reason Reason for disallowing satellite communication. |
| 13379 | * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the |
| 13380 | * operation. |
| 13381 | * |
| 13382 | * @throws SecurityException if the caller doesn't have required permission. |
| 13383 | */ |
| 13384 | public void removeSatelliteAttachRestrictionForCarrier(int subId, |
| 13385 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13386 | @NonNull IIntegerConsumer callback) { |
| 13387 | enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier"); |
| 13388 | final long identity = Binder.clearCallingIdentity(); |
| 13389 | try { |
| 13390 | mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason, |
| 13391 | callback); |
| 13392 | } finally { |
| 13393 | Binder.restoreCallingIdentity(identity); |
| 13394 | } |
| 13395 | } |
| 13396 | |
| 13397 | /** |
| 13398 | * Get reasons for disallowing satellite communication, as requested by |
| 13399 | * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
| 13400 | * |
| 13401 | * @param subId The subId of the subscription to request for. |
| 13402 | * |
| 13403 | * @return Integer array of reasons for disallowing satellite communication. |
| 13404 | * |
| 13405 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13406 | */ |
| 13407 | public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier( |
| 13408 | int subId) { |
| 13409 | enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier"); |
| 13410 | final long identity = Binder.clearCallingIdentity(); |
| 13411 | try { |
| 13412 | Set<Integer> reasonSet = |
| 13413 | mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId); |
| 13414 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13415 | } finally { |
| 13416 | Binder.restoreCallingIdentity(identity); |
| 13417 | } |
| 13418 | } |
| 13419 | |
| 13420 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13421 | * Request to get the signal strength of the satellite connection. |
| 13422 | * |
| 13423 | * @param subId The subId of the subscription to request for. |
| 13424 | * @param result Result receiver to get the error code of the request and the current signal |
| 13425 | * strength of the satellite connection. |
| 13426 | * |
| 13427 | * @throws SecurityException if the caller doesn't have required permission. |
| 13428 | */ |
| 13429 | @Override |
| 13430 | public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) { |
| 13431 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13432 | final long identity = Binder.clearCallingIdentity(); |
| 13433 | try { |
| 13434 | mSatelliteController.requestNtnSignalStrength(subId, result); |
| 13435 | } finally { |
| 13436 | Binder.restoreCallingIdentity(identity); |
| 13437 | } |
| 13438 | } |
| 13439 | |
| 13440 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13441 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13442 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13443 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13444 | * |
| 13445 | * @param subId The subId of the subscription to request for. |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13446 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13447 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13448 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13449 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13450 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13451 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13452 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13453 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13454 | */ |
| 13455 | @Override |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13456 | public void registerForNtnSignalStrengthChanged(int subId, |
| 13457 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13458 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13459 | final long identity = Binder.clearCallingIdentity(); |
| 13460 | try { |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13461 | mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13462 | } finally { |
| 13463 | Binder.restoreCallingIdentity(identity); |
| 13464 | } |
| 13465 | } |
| 13466 | |
| 13467 | /** |
| 13468 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13469 | * If callback was not registered before, the request will be ignored. |
| 13470 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13471 | * @param subId The subId of the subscription to unregister for listening NTN signal strength |
| 13472 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13473 | * @param callback The callback that was passed to |
| 13474 | * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)} |
| 13475 | * |
| 13476 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13477 | */ |
| 13478 | @Override |
| 13479 | public void unregisterForNtnSignalStrengthChanged( |
| 13480 | int subId, @NonNull INtnSignalStrengthCallback callback) { |
| 13481 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13482 | final long identity = Binder.clearCallingIdentity(); |
| 13483 | try { |
| 13484 | mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback); |
| 13485 | } finally { |
| 13486 | Binder.restoreCallingIdentity(identity); |
| 13487 | } |
| 13488 | } |
| 13489 | |
| 13490 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13491 | * Registers for satellite capabilities change event from the satellite service. |
| 13492 | * |
| 13493 | * @param subId The subId of the subscription to request for. |
| 13494 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13495 | * |
| 13496 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13497 | * |
| 13498 | * @throws SecurityException if the caller doesn't have required permission. |
| 13499 | */ |
| 13500 | @Override |
| 13501 | @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged( |
| 13502 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13503 | enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged"); |
| 13504 | final long identity = Binder.clearCallingIdentity(); |
| 13505 | try { |
| 13506 | return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback); |
| 13507 | } finally { |
| 13508 | Binder.restoreCallingIdentity(identity); |
| 13509 | } |
| 13510 | } |
| 13511 | |
| 13512 | /** |
| 13513 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13514 | * If callback was not registered before, the request will be ignored. |
| 13515 | * |
| 13516 | * @param subId The subId of the subscription to unregister for satellite capabilities change. |
| 13517 | * @param callback The callback that was passed to. |
| 13518 | * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}. |
| 13519 | * |
| 13520 | * @throws SecurityException if the caller doesn't have required permission. |
| 13521 | */ |
| 13522 | @Override |
| 13523 | public void unregisterForSatelliteCapabilitiesChanged( |
| 13524 | int subId, @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13525 | enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged"); |
| 13526 | final long identity = Binder.clearCallingIdentity(); |
| 13527 | try { |
| 13528 | mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback); |
| 13529 | } finally { |
| 13530 | Binder.restoreCallingIdentity(identity); |
| 13531 | } |
| 13532 | } |
| 13533 | |
| 13534 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13535 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13536 | * |
| 13537 | * @param servicePackageName The package name of the satellite vendor service. |
| 13538 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13539 | * {@code false} otherwise. |
| 13540 | */ |
| 13541 | public boolean setSatelliteServicePackageName(String servicePackageName) { |
| 13542 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName); |
| 13543 | TelephonyPermissions.enforceShellOnly( |
| 13544 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13545 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13546 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13547 | "setSatelliteServicePackageName"); |
| 13548 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName); |
| 13549 | } |
| 13550 | |
| 13551 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13552 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13553 | * |
| 13554 | * @param servicePackageName The package name of the satellite gateway service. |
| 13555 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13556 | * {@code false} otherwise. |
| 13557 | */ |
| 13558 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13559 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13560 | TelephonyPermissions.enforceShellOnly( |
| 13561 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13562 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13563 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13564 | "setSatelliteGatewayServicePackageName"); |
| 13565 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13566 | } |
| 13567 | |
| 13568 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13569 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13570 | * |
| 13571 | * @param packageName The package name of the satellite pointing UI app. |
| 13572 | * @param className The class name of the satellite pointing UI app. |
| 13573 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13574 | * {@code false} otherwise. |
| 13575 | */ |
| 13576 | public boolean setSatellitePointingUiClassName( |
| 13577 | @Nullable String packageName, @Nullable String className) { |
| 13578 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13579 | + ", className=" + className); |
| 13580 | TelephonyPermissions.enforceShellOnly( |
| 13581 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13583 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13584 | "setSatelliteGatewayServicePackageName"); |
| 13585 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13586 | } |
| 13587 | |
| 13588 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13589 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13590 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13591 | * listening mode. |
| 13592 | * |
| 13593 | * @param timeoutMillis The timeout duration in millisecond. |
| 13594 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13595 | */ |
| 13596 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 13597 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 13598 | TelephonyPermissions.enforceShellOnly( |
| 13599 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 13600 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13601 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13602 | "setSatelliteListeningTimeoutDuration"); |
| 13603 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 13604 | } |
| 13605 | |
| 13606 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13607 | * This API can be used by only CTS to update the timeout duration in milliseconds whether |
| 13608 | * the device is aligned with the satellite for demo mode |
| 13609 | * |
| 13610 | * @param timeoutMillis The timeout duration in millisecond. |
| 13611 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13612 | */ |
| 13613 | public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) { |
| 13614 | Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis); |
| 13615 | TelephonyPermissions.enforceShellOnly( |
| 13616 | Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration"); |
| 13617 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13618 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13619 | "setDeviceAlignedTimeoutDuration"); |
| 13620 | return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis); |
| 13621 | } |
| 13622 | |
| 13623 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 13624 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 13625 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 13626 | * |
| 13627 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 13628 | * of the following values to enable the override: |
| 13629 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 13630 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 13631 | * To disable the override, use -1 for handoverType. |
| 13632 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 13633 | * delaySeconds after the emergency call starts. |
| 13634 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 13635 | */ |
| 13636 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 13637 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 13638 | TelephonyPermissions.enforceShellOnly( |
| 13639 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 13640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13641 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13642 | "setEmergencyCallToSatelliteHandoverType"); |
| 13643 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 13644 | handoverType, delaySeconds); |
| 13645 | } |
| 13646 | |
| 13647 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame^] | 13648 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 13649 | * |
| 13650 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 13651 | */ |
| 13652 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 13653 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 13654 | long locationCountryCodeTimestampNanos) { |
| 13655 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 13656 | + String.join(", ", currentNetworkCountryCodes) |
| 13657 | + ", locationCountryCode=" + locationCountryCode |
| 13658 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 13659 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 13660 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
| 13661 | TelephonyPermissions.enforceShellOnly( |
| 13662 | Binder.getCallingUid(), "setCachedLocationCountryCode"); |
| 13663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13664 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13665 | "setCachedLocationCountryCode"); |
| 13666 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes( |
| 13667 | reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode, |
| 13668 | locationCountryCodeTimestampNanos); |
| 13669 | } |
| 13670 | |
| 13671 | /** |
| 13672 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 13673 | * access controller. |
| 13674 | * |
| 13675 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 13676 | * otherwise. |
| 13677 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 13678 | */ |
| 13679 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 13680 | String s2CellFile, long locationFreshDurationNanos, |
| 13681 | List<String> satelliteCountryCodes) { |
| 13682 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 13683 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 13684 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 13685 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 13686 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 13687 | TelephonyPermissions.enforceShellOnly( |
| 13688 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 13689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13690 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13691 | "setSatelliteAccessControlOverlayConfigs"); |
| 13692 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed, |
| 13693 | s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 13694 | } |
| 13695 | |
| 13696 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 13697 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 13698 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 13699 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 13700 | * |
| 13701 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 13702 | * satellite modem or not. |
| 13703 | * |
| 13704 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 13705 | */ |
| 13706 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 13707 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 13708 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 13709 | + "disabled"); |
| 13710 | return false; |
| 13711 | } |
| 13712 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 13713 | TelephonyPermissions.enforceShellOnly( |
| 13714 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 13715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13716 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13717 | "setShouldSendDatagramToModemInDemoMode"); |
| 13718 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 13719 | shouldSendToModemInDemoMode); |
| 13720 | } |
| 13721 | |
| 13722 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13723 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 13724 | * |
| 13725 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 13726 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 13727 | * identifier is sent in the clear, which has privacy implications for the user. |
| 13728 | * |
| 13729 | * @param enable if notifications about disclosure events should be enabled |
| 13730 | * @throws SecurityException if the caller does not have the required privileges |
| 13731 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13732 | */ |
| 13733 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13734 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13735 | enforceModifyPermission(); |
| 13736 | checkForIdentifierDisclosureNotificationSupport(); |
| 13737 | |
| 13738 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 13739 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 13740 | editor.apply(); |
| 13741 | |
| 13742 | // Each phone instance is responsible for updating its respective modem immediately |
| 13743 | // after we've made a preference change. |
| 13744 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13745 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 13746 | } |
| 13747 | } |
| 13748 | |
| 13749 | /** |
| 13750 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 13751 | * |
| 13752 | * @throws SecurityException if the caller does not have the required privileges |
| 13753 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 13754 | */ |
| 13755 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 13756 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 13757 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 13758 | checkForIdentifierDisclosureNotificationSupport(); |
| 13759 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 13760 | } |
| 13761 | |
| 13762 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13763 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 13764 | * |
| 13765 | * <p>This method behaves in one of the following ways: |
| 13766 | * <ul> |
| 13767 | * <li>return true : if the calling package has the appop permission {@link |
| 13768 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 13769 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 13770 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 13771 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 13772 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 13773 | * </ul> |
| 13774 | */ |
| 13775 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 13776 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 13777 | for (Phone phone : PhoneFactory.getPhones()) { |
| 13778 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 13779 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 13780 | return true; |
| 13781 | } |
| 13782 | } |
| 13783 | return false; |
| 13784 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13785 | |
| 13786 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13787 | * @return The subscription manager service instance. |
| 13788 | */ |
| 13789 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 13790 | return SubscriptionManagerService.getInstance(); |
| 13791 | } |
| 13792 | |
| 13793 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 13794 | * Class binds the consumer[callback] and carrierId. |
| 13795 | */ |
| 13796 | private static class CallerCallbackInfo { |
| 13797 | private final Consumer<Integer> mConsumer; |
| 13798 | private final int mCarrierId; |
| 13799 | |
| 13800 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 13801 | mConsumer = consumer; |
| 13802 | mCarrierId = carrierId; |
| 13803 | } |
| 13804 | |
| 13805 | public Consumer<Integer> getConsumer() { |
| 13806 | return mConsumer; |
| 13807 | } |
| 13808 | |
| 13809 | public int getCarrierId() { |
| 13810 | return mCarrierId; |
| 13811 | } |
| 13812 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13813 | |
| 13814 | /* |
| 13815 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 13816 | * But the context that is passed in is unused if the phone app is already alive. |
| 13817 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 13818 | */ |
| 13819 | @VisibleForTesting |
| 13820 | public void setPackageManager(PackageManager packageManager) { |
| 13821 | mPackageManager = packageManager; |
| 13822 | } |
| 13823 | |
| 13824 | /* |
| 13825 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 13826 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 13827 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 13828 | */ |
| 13829 | @VisibleForTesting |
| 13830 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 13831 | mFeatureFlags = featureFlags; |
| 13832 | } |
| 13833 | |
| 13834 | /** |
| 13835 | * Make sure the device has required telephony feature |
| 13836 | * |
| 13837 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 13838 | */ |
| 13839 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 13840 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 13841 | if (callingPackage == null || mPackageManager == null) { |
| 13842 | return; |
| 13843 | } |
| 13844 | |
| 13845 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 13846 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
| 13847 | Binder.getCallingUserHandle())) { |
| 13848 | return; |
| 13849 | } |
| 13850 | |
| 13851 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 13852 | throw new UnsupportedOperationException( |
| 13853 | methodName + " is unsupported without " + telephonyFeature); |
| 13854 | } |
| 13855 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 13856 | } |